Hi All...
I am trying to design a large scale GUI, and after reading several MVC articles I still have some question on writing the GUI code.
for flexability I split the code to classes:
1) How can I notify on event(exp: actionPerformed), to other widgets located in separated classes which not visible(I attached a code describing this issue, every class would be in separated class)
Note
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class BaseComp1 implements ActionListener{
JButton button1;
public void actionPerformed(ActionEvent e){
// notify DrawingArea instance, an action performed
}
}
class BaseComp2 implements ActionListener{
JButton button2;
public void actionPerformed(ActionEvent e){
// notify DrawingArea instance, an action performed
}
}
public class MainComp{
BaseComp1 base1 ;
BaseComp2 base2;
public MainComp(){
base1 = new BaseComp1();
base2 = new BaseComp2();
}
}
public class drawingArea{
public void drawStuff(){ // draw stuff when actionPerform in one of BaseComp* instance
}
}
public class GUI{
drawingArea drawing;
MainComp mainComp;
public GUI(){ // need to connect BaseComp* instances in MainComp instance to
// notify drawingArea on actionPerform event
drawing = new drawingArea();
mainComp = new MainComp();
}
}
2) If a solution is available but not recommended, is the preferred coding design for large GUI is to write all of it in the same class ?? any suggestion will excepted joyfully..
I would like to thanks in advance for any help
Best Regards
YyYo
Edited by: YyYo on May 25, 2010 12:35 PM
Edited by: YyYo on May 25, 2010 12:36 PM