...
button.setOnClickListener(new OnClickListener() {
void onClick(...) {
// NOTE: passing data from current view
c1.fireEvent(new Event(Events.BYE_C1, getData()));
}
});
onEvent(Event e) {
...
if ( Events.BYE_C1.equals(e) ) {
// do controller finalizatoin
fireEvent(Events.C1_DESTROYING);
// NOTE: setting to the model data from first view
model.setSomething(e.getData());
// creating second controller
Controller c2 = new Controller();
// creating second window (NOTE: may be done inside the second controller on "HELLO_C2" event)
Window w2 = new Window(c2);
// init second controller
c2.fireEvent(Events.HELLO_C2);
// show views
c2.fireEvent(Events.C2_STARTED)
}
}
Events.APP_INIT
:void main () {
Controller c = new Controller();
Model m = new Model();
c.setModel(m);
// controller is also event listener
c.addEventListener(c);
c.fireEvent(Events.APP_INIT);
c.fireEvent(Events.APP_STARTED);
}
class Controller implements Listener {
// root panel
JFrame panel;
...
onEvent(Event e) {
if ( Events.APP_INT.equals(e) ) {
panel = new JFrame();
View v1 = new View();
View v2 = new View();
// filling panel content
panel.add(v1);
panel.add(v2);
// registering event listeners
c.addEventListener(v1);
c.addEventListener(v2);
} else if ( Events.APP_STARTED ) {
// NOTE: here we divided view creation in 2 steps: init step and show step
panel.show();
}
}
...
}
void main () {
Controller c = new Controller();
Model m = new Model();
c.setModel(m);
JFrame panel = new JFrame();
View v1 = new View();
View v2 = new View();
// filling panel content
panel.add(v1);
panel.add(v2);
// registering event listeners
c.addEventListener(v1);
c.addEventListener(v2);
// controller is also event listener
c.addEventListener(c);
c.fireEvent(Events.APP_INIT);
c.fireEvent(Events.APP_STARTED);
}