File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Switching between two forms

 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can look up for JDialog or may be JInternalFrame
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 70
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call dispose() on the JFrame object, which you wish to close.
 
Digen Mahara
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic