Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPanel and JFrame listener

 
Kah Fai Tan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11090
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kah Fai Tan,
Welcome to the Ranch.

Check out card layout.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up the Sun Swing tutorial on CardLayout.
 
Kah Fai Tan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11090
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic