mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-10 02:13:07 +01:00
feat(ch 7): listeners ex added - LluviaListener
This commit is contained in:
@@ -30,8 +30,8 @@ public class IntroduccionNumeros {
|
||||
*/
|
||||
private static void fireNumeroImparListener(int numeroImparIntroducido) {
|
||||
NumeroImparEvent event = new NumeroImparEvent(numeroImparIntroducido);
|
||||
for (int i = listNumeroImparListeners.size() - 1; i >= 0; i--) {
|
||||
listNumeroImparListeners.get(i).numeroImparIntroducido(event);
|
||||
for (NumeroImparListener listener : listNumeroImparListeners) {
|
||||
listener.numeroImparIntroducido(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ public class Perro implements NumeroImparListener {
|
||||
public void numeroImparIntroducido(NumeroImparEvent e) {
|
||||
System.out.println("Soy un perro y me han notificado la introducción de un número "
|
||||
+ "impar: " + e.getNumeroIntroducido());
|
||||
IntroduccionNumeros.removeNumeroImparListener(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package tutorialJava.capitulo7_Recursos.lluviaListener;
|
||||
|
||||
public interface InteresadoLLuviaListener {
|
||||
|
||||
public void estaLloviendo(InteresadoLluviaEvent event);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package tutorialJava.capitulo7_Recursos.lluviaListener;
|
||||
|
||||
public class InteresadoLluviaEvent {
|
||||
|
||||
private int litrosPorMetro;
|
||||
|
||||
public InteresadoLluviaEvent() {
|
||||
super();
|
||||
}
|
||||
|
||||
public int getLitrosPorMetro() {
|
||||
return litrosPorMetro;
|
||||
}
|
||||
|
||||
public void setLitrosPorMetro(int litrosPorMetro) {
|
||||
this.litrosPorMetro = litrosPorMetro;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package tutorialJava.capitulo7_Recursos.lluviaListener;
|
||||
|
||||
public class ProgramaRadio implements InteresadoLLuviaListener {
|
||||
|
||||
public ProgramaRadio () {
|
||||
Aemet.addInteresadoLluviaListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void estaLloviendo(InteresadoLluviaEvent event) {
|
||||
System.out.println("Soy un programa de radio y me notifican que llueve");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package tutorialJava.capitulo7_Recursos.lluviaListener;
|
||||
|
||||
public class Telediario implements InteresadoLLuviaListener {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Telediario() {
|
||||
Aemet.addInteresadoLluviaListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void estaLloviendo(InteresadoLluviaEvent event) {
|
||||
System.out.println("Soy un telediario y me dicen que llueve "
|
||||
+ event.getLitrosPorMetro() + " litros por metro");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user