Parent Form in Java

J

jawad.safiszaaz

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.
 
J

Joe Attardi

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();
}

}
 
M

Mark Space

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top