Win a copy of Event Streams in Action this week in the Java in General 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Call new form (JFrame) from application

 
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.
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!