*
The moose likes Swing / AWT / SWT and the fly likes Switching between two forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Switching between two forms" Watch "Switching between two forms" New topic
Author

Switching between two forms

Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

Hi,
I have a form which takes username and password and authenticates the user. I need to open a new form once OK is clicked. How to I do it?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6



Swastik
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

You can look up for JDialog or may be JInternalFrame


Mohamed Sanaulla | My Blog
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> I need to open a new form once OK is clicked.

that is most unusual - the form is to open before the validation of username/password?

anyway, can you comfortably display a JFrame?

if so, your program should open with a JDialog requesting username/password. In the background
construct your JFrame, but do not set it to visible.

When the OK button is clicked:
validate username/password
if valid, frame.setVisible(true) and dialog.dispose()
Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

I tried this code and it worked fine.

I now want to know how to close the parent frame automatically when the OK button is clicked.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

Call dispose() on the JFrame object, which you wish to close.
Digen Mahara
Greenhorn

Joined: Dec 23, 2011
Posts: 23

Shikha Upadhyaya wrote:
I now want to know how to close the parent frame automatically when the OK button is clicked.


Shikha as Michael Dunn said use the dispose() method

eg : if your parent frame is Form1 then it works like this






Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
Agree with Mohammed earlier. You want a JDialog, which disappears after use. Much better than trying to create two frames and dispose of the second.
Actually, you can probably use the setDefaultCloseOperation method on the frame, with DISPOSE_ON_CLOSE, so the dispose() call may be unnecessary.
Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

Digen Mahara wrote:Shikha as Michael Dunn said use the dispose() method
eg : if your parent frame is Form1 then it works like this





I am not able to do this because my code is something like this:
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1447
    
    6

Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

Thanks all
 
jQuery in Action, 2nd edition
 
subject: Switching between two forms
 
Similar Threads
it is possible to do validations through Form class and Validations.xml file?
[SOLVED] Something wrong with DynaActionForms
JComboBox and ArrayList
Page attribute in validator
making the table scrollable