Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to switch frame use JButton?

 
taiki bao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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!!!
 
Pat Hays
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
hey cheers mate. really helpful!!
 
taiki bao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic