File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to switch frame use JButton? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to switch frame use JButton?" Watch "How to switch frame use JButton?" New topic
Author

How to switch frame use JButton?

taiki bao
Greenhorn

Joined: Apr 01, 2005
Posts: 4
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

Joined: Aug 20, 2004
Posts: 138
Hi omega,

See the following code:
------------
jButton1_actionPerformed(ActionEvent e)
{
frame1.setVisible(false); //hide the First frame
frame2.setVisible(true); //go to CheckIn frame
}


Download Java GUI Builder, <a href="http://www.mars3000.com" target="_blank" rel="nofollow">http://www.mars3000.com</a>
taiki bao
Greenhorn

Joined: Apr 01, 2005
Posts: 4
hey cheers mate. really helpful!!
taiki bao
Greenhorn

Joined: Apr 01, 2005
Posts: 4
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

Joined: Jan 29, 2003
Posts: 8791
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?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
 
 
subject: How to switch frame use JButton?