Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Switching between two forms

 
Ranch Hand
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can look up for JDialog or may be JInternalFrame
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Call dispose() on the JFrame object, which you wish to close.
 
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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






 
Marshal
Posts: 79019
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic