public void Model {
private SwingPropertyChangeSupport spcs;
public void updatedb();
public void addPropertyChangeListener(PropertyChangeListener listener)
}
public void Gui {
private JFrame view;
Gui() {
view = new JFrame();
init();// for initilizing ui components
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
view.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
void addListener(ActionListener a);
void init();
void updateGUI();
}
public void Controller implements ActionListener,PropertyChangeListener {
Model m;
Gui g;
public void PropertyChange(PropertyChangeEvent e);
public void actionPerformed(ActionEvent e)
Controller(Model m,Gui g){}
}
What is the correct of way of passing messages between 3 classes MVC message passsing Image How to extend it for multiple controllers and views?I have read SO answers The MVC pattern and SWING saying this implementation is not efficient?
And whether it is right to make Controller ActionListener and PropertyChangeListener?Will it make GUI sluggish when I call updatedb() inside actionperformed()?I also read about View having reference of Controller which maps gui actions to model actions. Is this way more efficient?
Which part of code should be inside EventQueue.invokeLater? Is it right to put init() function outside run()?Or Should I wrap the whole gui class inside run?
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Gui view = new Gui();
} catch (Exception e) {
e.printStackTrace();
}
}
});