For example I have two Java Classes:
public class MainFrame extend JFrame implements ActionListener{
public SouthPanel SPanel = new SouthPanel();
public int foo = 0;
MainFrame() {
//MainFrame config
this.add(SPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
}
}
public class SouthPanel extend Panel {
public JButton openNewWindow = new JButton();
public JLabel label = new Label();
SouthPanel() {
//button and label config
//adding component
}
}
What can i do to make a feature that when i click a button from the SouthPanel and foo in MainFrame will change.
So, in most UI frameworks, you have a concept of an "observer pattern", this is way for interested parties to register interest been notified when something happens to the object.
Swing makes use of "listeners" to facilitate this basic concept. You're not stuck to using the listeners that Swing defines and you can create your own, for example...
This example is deliberately long winded, as you don't "always" need to create an event object, but it is a good way to pass back information to the observer, as it might not actually have a direct reference to object it's monitoring.