I am new on Java.
I have developed an application with some different JPanels
(using a BorderLayout
, 3 panels in this case).
In panel 1, I have a JLabel and a variable (a class) that is related with its value (method get); in panel 2, I updated the value of the variable (method set) because it is done when an action is performed in this second panel.
How Could I get the value of the JLabel in panel 1 updated?
I don't know how to trigger an event or something similar after updating the value from panel 2 and how to make panel 1 to listen to this change.
Let me explain a bit more. I have a JFrame with two JPanels and I update the model from one panel. Once the model is updated, the JLabel from the other JPanel should be updated: Main: JFrame
public class MainClass extends JFrame
{
public MainClass()
{
// JPanel 1
....
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
setLocationRelativeTo(null);
setTitle("Test");
setResizable(false);
setVisible(true);
// JPanel 1
this.add(west, BorderLayout.WEST);
// JPanel 2
this.add(board, BorderLayout.CENTER);
}
public static void main(String[] args)
{
// put your code here
new MainClass ();
}
}
JPanel 1
public class West extends JPanel
{
contFase = new Contador(titulo, valor);
JLabel lblTitulo;
...
lblTitulo.setText = contFase.getText();
this.add(lblTitulo);
...
}
JPanel 2
public class Board extends JPanel implements ActionListener
{
....
public void actionPerformed(ActionEvent e)
{
...
//Here Label of panel 1 should be updated with the model
contFase.setValor(contFase.getValor() + pacman.comerElemento(fase.getPacdots(), fase.getPowerPellets()));
...
}
}