This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JPanel and JFrame listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel and JFrame listener" Watch "JPanel and JFrame listener" New topic
Author

JPanel and JFrame listener

Kah Fai Tan
Greenhorn

Joined: Jun 16, 2007
Posts: 3
Hi,

Currently, I am doing a program. I will have few JPanel and only one JFrame.

By default, JFrame will show a JPanel (Panel A), in full screen.

I implement a button in Panel A to call the Panel B.

How am I to realize this coding?

Panel A will be either remove or disappear from the JFrame and add Panel B into the JFrame.

Thank you
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Kah Fai Tan,
Welcome to the Ranch.

Check out card layout.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Look up the Sun Swing tutorial on CardLayout.
Kah Fai Tan
Greenhorn

Joined: Jun 16, 2007
Posts: 3
That means I need to create a JButton with the listener on JFrame, I only be able to switch the JPanel?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

The button will be the trigger for the switching action. Yes. But the button need not be the only trigger. You can have a menu based trigger, or a keyboard based trigger or even a mouse based trigger. It all depends on what your requirement is.
 
 
subject: JPanel and JFrame listener