• Post Reply Bookmark Topic Watch Topic
  • New Topic

Correct way to navigate from one form to another

 
Raj kalaria
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Mark post as helpful
  • send pies
  • 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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!