Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-30-2007, 05:22 PM
Member
 
Join Date: Dec 2007
Posts: 4
vassil_zorev is on a distinguished road
Can't synchronize multiple JPanels in a JFrame
Hello,
I've recently started using swing for creating User Interfaces and here is a difficulty I cannot overcome. My application has a main class and four JPanel forms.
The main class has a function that creates a JFrame and loads in it an instance of the first "JPanel" class. This has three radio buttons in a group and a JButton with the below function:

Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: if (jRadioButton1.isSelected()) { JOptionPane.showMessageDialog(null, "Beginner"); this.selection = 1; } else if (jRadioButton2.isSelected()) { JOptionPane.showMessageDialog(null, "Intermediate"); this.selection = 2; } else if (jRadioButton3.isSelected()) { JOptionPane.showMessageDialog(null, "Advanced"); this.selection = 3; } else { JOptionPane.showMessageDialog(null, "Make a selection!"); } }
selection is a public int member of NewJPanel (fst JPanel class)

Here is the Main class:

Code:
public Main() { } public void PlayAGame() { JFrame myFrame = new JFrame("Difficulty selection:"); NewJPanel panel = new NewJPanel(); myFrame.setSize(256,256); myFrame.setDefaultCloseOperation(myFrame.EXIT_ON_CLOSE); myFrame.getContentPane().add(panel); myFrame.pack(); myFrame.setVisible(true); switch (panel.selection) { case 1: { NewJPanel1 panel1 = new NewJPanel1(); myFrame.getContentPane().remove(panel); myFrame.getContentPane().add(panel1); break; } case 2: { NewJPanel2 panel2 = new NewJPanel2(); myFrame.getContentPane().remove(panel); myFrame.getContentPane().add(panel2); break; } case 3: { NewJPanel3 panel3 = new NewJPanel3(); myFrame.getContentPane().remove(panel); myFrame.getContentPane().add(panel3); break; } default: { break; } } } public static void main(String ar[]){ Main myMain = new Main(); myMain.PlayAGame(); }
Here is what I want the code to do:
Load a NewJPanel in the frame, the user makes a choice and clicks the button, then PlayAGame() (using the switch) unloads the NewJPanel and loads the suitable Panel in the frame.

Here is what it does:
NewJPanel is loaded, I make a choice, click the button and nothing happens; NewJPanel is still in the frame

I need help, please!

Regards,
Vassil Zorev
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to synchronize blocks instead of entire methods Java Tip java.lang 0 04-09-2008 07:39 PM
How to synchronize threads on an object Java Tip java.lang 0 04-09-2008 07:39 PM
Problems with JPanels and displaying Mastergeek666 AWT / Swing 1 01-19-2008 01:32 AM
How to add Images to JPanels? Soda New To Java 3 12-08-2007 06:54 PM
Help with JFrame Albert AWT / Swing 2 07-04-2007 05:44 AM


All times are GMT +3. The time now is 03:18 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org