I'm currently learning to use the PropertyChangeListener and PropertyChangeSupport class. I'm a bit stuck in the part where the listener receives the event so I'll need some help with this part.
In my program there are 2 classes:
- One, the controller, implements the PropertyChangeListener
- The other, the model, implements the propertyChanegSupport
Controller:
public class Controlador implements PropertyChangeListener {
private ControlAccesos modelo;
private GUIpanel vistaPan;
private GUIsenal vistaSen;
public Controlador(GUIpanel vista1, GUIsenal vista2, ControlAccesos model){
modelo=model;
vistaPan = vista1;
vistaSen = vista2;
modelo.addPropertyChangeListener(this);
}
public void propertyChange(PropertyChangeEvent evt) {
System.out.print("Resultado");
if (evt.getPropertyName().equals("mensaje")){
vistaPan.refrescaMensaje((String)evt.getNewValue());
}
}
}
Model:
/**
* Clase principal del sistema de control de accesos a la facultad.
*/
public class ControlAccesos
{
/**
* Mesaje shown in the GUI
*/
private String mensaje;
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
.
.
.
public void TarjetaDetectada( String usuario )
{
state.TarjetaDetectada(this, usuario);
changeSupport.firePropertyChange("mensaje",this.mensaje,this.mensaje);
}
public void addPropertyChangeListener( PropertyChangeListener listener ){
changeSupport.addPropertyChangeListener(listener);
}
The problem is that the code never reaches the propertyChange function ("Resultado" is never printed on the screen).
Thank you in advance.