How to seperate GUI from Program logic?

Hi,

I have a JApplet , which needs to consist of Menubar, ToolBar , JPanel (to draw objects) and Status Bar.

I made seperate java classes for toolBar.java , panel.java and statusBar.java.

Menubar was added directly on the JApplet

I integrated them in Main JApplet as

publicclass NewJAppletextends javax.swing.JApplet{

/** Initializes the applet NewJApplet */

publicvoid init(){

try{

java.awt.EventQueue.invokeAndWait(new Runnable(){

publicvoid run(){

initComponents();// Creates Menu Bar

getContentPane().add(new Toolbar());

getContentPane().add(new Panel());

getContentPane().add(new Statusbar());

}

});

}catch (Exception ex){

ex.printStackTrace();

}

}

}

But this does not work, Only i see is menubar.

I dont understand what is missing,

Thanks

[1710 byte] By [kanchisaa] at [2007-11-26 16:48:12]
# 1

The results of your add() calls will depend on the layout manager used by the content pane. For instance, if it's using BorderLayout, an unconstrained add() call refers to the center - and only one component can exist in that location.

Set your layout manager and constraints explicitly.

Not sure what any of this has to do with your thread title, though :o)

itchyscratchya at 2007-7-8 23:15:44 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for your help.Could you please suggest what layout should be used in such situation.which is mostly for JApplet.
kanchisaa at 2007-7-8 23:15:44 > top of Java-index,Desktop,Core GUI APIs...
# 3
Typically you would use JApplet.setJMenuBar() for the menu bar, then use a BorderLayout and add the toolbar, main content and status bar to 'NORTH,' 'CENTER' and 'SOUTH' respectively.
itchyscratchya at 2007-7-8 23:15:44 > top of Java-index,Desktop,Core GUI APIs...
# 4

I used BorderLayout for the JApplet, added Menubar to it, and then added following code

contentPane.add(toolbar,BorderLayout.NORTH);

contentPane.add(panel,BorderLayout.CENTER);

contentPane.add(statusBar,BorderLayout.SOUTH);

Now the problem is, i cant see toolbar, it does not come after menubar .

How to solve it ? : (

kanchisaa at 2007-7-8 23:15:44 > top of Java-index,Desktop,Core GUI APIs...
# 5
Use a JPanel with BorderLayout to contain your toolbar/panel/status bar. Set that as the applet's content pane (ie replace the content pane rather than add to it). Set the menu bar as the applet's menu bar.
itchyscratchya at 2007-7-8 23:15:44 > top of Java-index,Desktop,Core GUI APIs...