Results 1 to 3 of 3
Thread: JPanel add/remove in a JFrame
- 03-28-2011, 04:30 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
JPanel add/remove in a JFrame
Whenever It try to switch panels by adding a new one and removing the old one (like on the bold code below), the program (or its display) freezes. Is there any code that I need to add/change? Please help. Many Thanks :D
Java Code:public class Game { JFrame myFrame = new JFrame (); Board back = new Board(); CharacterManager charac = new CharacterManager(); TitleScreen TS = new TitleScreen(); int dispState = 0; public Game() { back.setOpaque(false); charac.setOpaque(false); myFrame.setSize(600,700); myFrame.setResizable(false); myFrame.setVisible(true); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.getContentPane().add(TS); myFrame.addMouseListener(new Events()); myFrame.addMouseMotionListener(new Events()); } // Mouse Events Class public class Events implements MouseListener, MouseMotionListener, KeyListener { public void mouseMoved(MouseEvent e) { ... } public void mouseClicked(MouseEvent e) { //Title Screen if(dispState == 0) { if(TS.mouseAtStart) { dispState = 1; [B]myFrame.getContentPane().remove(TS); myFrame.getContentPane().add(back);[/B] } else if(TS.mouseAtHelp) { } else if(TS.mouseAtScores) { } else if(TS.mouseAtExit) { System.exit(0); } } //Board else if(dispState == 1) { } } .... }
- 03-28-2011, 06:14 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,604
- Rep Power
- 5
What do you mean it freezes? Are there exceptions thrown? If you dynamically add components to a realized Container (in this case a visible JFrame) call revalidate
- 03-28-2011, 07:28 PM #3
Similar Threads
-
jpanel in jframe-pls help
By archanaanbu in forum Java AppletsReplies: 3Last Post: 02-14-2011, 05:01 AM -
How do you remove the X in the Title Bar in a Jframe
By RickAintree in forum New To JavaReplies: 5Last Post: 02-08-2011, 04:15 PM -
jList - add/remove items and query - using jFrame Form
By ArneBassez in forum AWT / SwingReplies: 2Last Post: 12-01-2010, 12:42 PM -
Right-clicking a rectangle on a JFrame to remove it
By busdude in forum New To JavaReplies: 4Last Post: 02-20-2009, 02:44 AM -
how to remove all component in container(Jpanel)
By SaYuNaRa in forum New To JavaReplies: 3Last Post: 04-17-2008, 04:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks