Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Parent Form in Java

Thread view: 
jawad.safiszaaz@gmail.com - 13 Dec 2007 06:41 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.
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.