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.