• 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

Correct way to navigate from one form to another

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I trying to develop a small swing application,
I have two frames one frame is loggin screen and the 2nd frame is a simple frame with contain a form

The login frame will have an "Ok" button and once the "Ok" button is clicked, I want my 2nd frame (which is form) to display.
I have written that piece of code, but want to make sure i do it correctly


Name of frames
1)Login Frame
2)UserConnectedFrameSuccess


This is the Action code of the Ok button present in Login Frame
*******************************************
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("Ok Button Pressed");
setVisible(false);
UserConnectedFrameSuccess ucf = new UserConnectedFrameSuccess();
ucf.setVisible(true);

**********************************************************************

My concerns are
1) if one user passes the login screen is it advisable to completly close it or to hide it. Here is have hidden it becoz i did not know how to close the login fram and display the other frame.

I hope i have explained it nicely. Any help would be appreciated
 
Marshal
Posts: 79412
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably the easiest way to get rid of the login frame is to use its dispose() method.

You are declaring the next frame inside the actionPerformed method; do you really want it to be a local variable in the method?

Apart from that it looks all right to me. I am not used to this method; I usually use the ordinary addActionListener(new ActionListener() . . . form.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if there is any delay in showing the frame (after logging in),
you may want to consider creating UserConnectedFrameSuccess() while the
login dialog is showing, then on successful login, show the frame,
and dispose the dialog
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic