Hi i am facing some problems about making a parent form in java so can
any one guide me
the problem is that i want to make a standard form or window which
controls all the other form in a way that all of the menus of the
parent forms can perform their functionalities on the child form can
any one give me the idea.
Andrew Thompson - 13 Dec 2007 08:52 GMT
>Hi i am facing some problems about making a parent form
There are no such classes in J2SE. If such exist in
you IDE, try either..
A) F1, or ()perhaps more productively, ..
B) <http://java.sun.com/docs/books/tutorial/>
>..in java [sic] so can any one guide me...
Try RTFM first.

Signature
Andrew Thompson
http://www.physci.org/
Joe Attardi - 13 Dec 2007 17:32 GMT
> Hi i am facing some problems about making a parent form in java so can
> any one guide me
> the problem is that i want to make a standard form or window which
> controls all the other form in a way that all of the menus of the
> parent forms can perform their functionalities on the child form can
> any one give me the idea.
Just have the parent form keep a reference to the child form in a member
variable. Then the [J]MenuItems can get this reference to the child form
and do as they please.
public class ParentForm extends JFrame {
private JFrame childForm;
public void showChildForm() {
childForm = new JFrame();
}
}
Mark Space - 13 Dec 2007 19:43 GMT
> Hi i am facing some problems about making a parent form in java so can
> any one guide me
> the problem is that i want to make a standard form or window which
> controls all the other form in a way that all of the menus of the
> parent forms can perform their functionalities on the child form can
> any one give me the idea.
You should not use a parent-child relationship, in my opinion.
Make the windows separate objects.
Then, in your "parent" window, leave actionListener methods exposed so
you can install methods at runtime.
public MyMainApplicationWindow extends JFrame {
private JMenuBar menuBar;
private JMenu helpMenu;
private JMenuItem aboutMenuItem;
public MyMainApplicationWindow() {
super( "My App Name");
menuBar = new JMenuBar();
helpMenu = new Jmenu( "Help" );
aboutMenuItem = new JMenuItem( "About My App..." );
helpMenu.add( aboutMenuItem );
menuBar.add( helpMenu );
this.setMenuBar( menuBar );
this.pack();
this.setSize( 200, 200 );
this.setLocationRelativeTo( null );
}
public void setAboutAction( ActionListener a ) {
aboutMenuItem.addActionListener( a );
}
}
Now you can choose at run time what "About My App" does. This is
important for testing. In a small app (homework) it won't matter, but
anything larger you'll want to test these two windows separately.
Binding them at runtime is one way to ease your testing.
Note: code not compiled.