I recently starting learning Java, I have a pretty good grasp on C/C++ and wanted to expand my horizons. Anyway, I have being using the Headfirst Java book and recently finished the chapters on GUI. One thing that wasn't covered by the book was how to deal with child windows. I plan on using Java to make a time card system for my work place and anyone else that needs it (secondary question : When I finish my project could I post it on daniweb so others could download the source code to use/improve it?). So what I mean by child windows would be something like: The user would start on a name/password screen, after entering their information the login window would be replaced by a window that has the correct options for a user of his/her access level.
Any help on a class I need to research etc. would be appreciated. Thanks in advance.

When the button is clicked you can hide, or better dispose(I think that that is the name of the method of the JFrame class) and create new window.

class JLogin extends JFrame ... {

..

  public void methodUsedWhenLoginButtonClicked(ActionEvent evt) {
      JMainPage mainPage = new JMainPage();
      mainPage.setVisible(true);
      this.dispose(); // use this if you don't want to keep the state of the class. Meaning if you want to close completely the window and forget lose all the values of its attributes.
  }

..

}

For making a back-forward page:

class JFirstPage extends JFrame .... {
   private JSecondPage secondPage = null;   

   public JFirstPage() {
     super();
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      if (secondPage==null) secondPage = new JSecondPage(this); // passing it to the next window
      secondPage.setVisible(true); // showing the next window
   }

}
class JSecondPage extends JFrame .... {
   private JFirstPage firstPage = null;   

   public JSecondPage(JFirstPage firstPage) {
     super();
     this.firstPage= firstPage;
     ......
   }

   public void buttonClicked(ActiobEvent evt) {
      this.setvisible(false); // hiding this window
      firstPage.setVisible(true); // showing the previous window. Keeping ALL the values it had (the values of the text fields or anything else)
   }

}

With the first way you "dispose" the window and you lose the values it had and if you want to open it again, you need to make a new one.

With the second way you pass the same instance to the other window through the constructor and you can hide or show which ever window you want

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.