Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

spliting GUI code to multiple classes

843807May 25 2010 — edited May 26 2010
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 23 2010
Added on May 25 2010
2 comments
136 views