MVC Java Swing qestion -


i want write application in java swing using mvc architecture, have problem using multiple controllers because dont know how this.

public class application {  public static void main(string[] args) {     application app = new application();     app.start();  } public void start() {      mainmodel model = new mainmodel();     mainview view = new mainview();     maincontroller controller = new maincontroller(view,model);     view.setvisible(true); }} 

maincontroller:

public class maincontroller {  private mainview theview; private mainmodel themodel;  public maincontroller(mainview theview, mainmodel themodel) {     this.themodel = themodel;     this.theview = theview;  }} 

mainview:

public class mainview extends jframe{ private jmenu menu = new jmenu();  public mainview() {     jpanel panel = new jpanel();      this.setdefaultcloseoperation(jframe.exit_on_close);     this.setsize(800,800);     panel.add(menu);      this.add(panel); }} 

i not put here because model empty.

okay, don't know how use multiple controllers. example: want create new controller usercontroller , don't know how implement this. should create new controller in maincontroller? if create usercontroller in maincontroller how use it?

just create usercontroller in application class added maincontroller.

example: if have 2 buttons can add actionlistener.

button1 usercontroller.dosomething();

button2 maincontroller.dosomeotherthings();

thats way use ;)


Comments