Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Call new form (JFrame) from application  RSS feed

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...I am building an application where I need to call a second frame based on the user clicking on a button on the first frame. Could someone give me an idea what code would instantiate the second frame? I have the Actionperformed method set up for the button. Thanks.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same code as creates your first frame; i.e., perhaps all you'll need is:

new MyOtherJFrameSubclass();
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still having trouble with the concept of getting this to work. I have a main class that sets up the frame for the JFrame (Login) class and then calls itself to start the application. This then starts the Login screen. I have a button on the login screen that I want to call up a change password frame. I placed the 'new ChangePassword()' code in the ActionEvent method of the change password button but the new frame is not coming up. thanks again for you help.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, whether "new ChangePassword()" is enough or not depends on what the ChangePassword constructor does. Some JFrame subclasses call setVisible(true) , for example, while some don't. If your JFrame class doesn't automatically make itself visible in this way, then you'll need another line of code to do that. But my point is that there's nothing special here: you just create the class and set it up in the same way that you created and set up the first frame in your application -- except that you do it in an event handler.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!