• 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

How to switch frame use JButton?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All!!
I suffer a trouble in UI design. I got several frames in the project, nearly finished the function in each single frame, but i cannot link them together.
for example: First frame1 = new First();
CheckIn frame2 = new CheckIn();

void jButton1_actionPerformed(ActionEvent e) {???}
what can i write into {???} to implement "press button in First frame then go to CheckIn frame?"

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

See the following code:
------------
jButton1_actionPerformed(ActionEvent e)
{
frame1.setVisible(false); //hide the First frame
frame2.setVisible(true); //go to CheckIn frame
}
 
taiki bao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey cheers mate. really helpful!!
 
taiki bao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
new troubles. I cannot invoke frame2 in frame2.setVisible(true);
I define Second frame2 = new Second(); in Main class.
is there any good idea?
BTW, did someone know any examples abt multi-frames in JAVA?

many thanks!!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can move some of the logic into a special class, often called a controller.

This starts to separate one frame from knowing anything about the other. Does that make enough sense to help?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
omega bao

Welcome to Javaranch! We don't have too many rules around here but we do have a Naming Policy. Please adjust your display name to meet these requirements. You can change your display name by clicking here

Thanks for your cooporation.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic