Results 1 to 5 of 5
Thread: Problems calling JPanel
- 04-14-2011, 06:33 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Problems calling JPanel
I am trying to build the navigation though my GUI.
On my first screen I have a few options that you can select. When you select the option is sets the new JPanel. From the new JPanel I can navigate back to my original screen as well.
Where my problem lies is when I try to navigate from the 1st JPanel to a 2nd JPanel. I cant figure out what I am doing wrong.
.Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MenuGUI extends JFrame implements ActionListener { CategoryGUI myCat; public MenuGUI(){ myCat = new CategoryGUI(); myCat.backButton.addActionListener(this); c = getContentPane(); contentPane = getContentPane(); contentPane.setLayout(null); declare my buttons and labels and stuff here } public void actionPerformed(ActionEvent e){ if(startButton == e.getSource()){ soundclip = "assets/sounds/click.wav"; Thread thread1 = new Thread(new soundClip(soundclip), "soundclip"); thread1.start(); setContentPane(myCat); myCat.setVisible(true); } if(myCat.backButton == e.getSource()){ this.setContentPane(c); } } }
DifficultyFlag is also a class that extends JPanel. It is the same in structure as Category GUI.Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class CategoryGUI extends JPanel implements ActionListener{ DifficultyFlags flagD; public CategoryGUI(){ contentPane = this; contentPane.setLayout(null); setSize(1100, 700); flagD = new DifficultyFlags(); declare my buttons and labels and stuff here } public void actionPerformed(ActionEvent e){ if(backButton == e.getSource()){ soundclip = "assets/sounds/click.wav"; Thread thread1 = new Thread(new soundClip(soundclip), "soundclip"); thread1.start(); } if(flagButton == e.getSource()){ soundclip = "assets/sounds/click.wav"; Thread thread1 = new Thread(new soundClip(soundclip), "soundclip"); thread1.start(); setContentPane(flagD); <--- ERROR HERE flagD.setVisible(true); } }
I receive an error where I try to set ContentPane to the new JPanel.
- 04-14-2011, 06:38 PM #2
What error are you getting? That's some pertinent information.
Hint- JPanel doesn't have a setContentPane() method.
Besides, CardLayout is your friend here.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 06:43 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
the error is:
cannot find symbol
symbol: method setContentPane(codejunkies.DifficultyFlags)
location: class codejunkies.CategoryGUI
which makes sense I suppose seeing as you said JPanel does not have setContentPane
I really cant go the Cardlayout route because my project is almost due and its nearly complete as well. I just dont have to the time to really learn it and make big changes.
I might not have done things the most optimal way, but its a learning experience and next project will be different im sure.
- 04-14-2011, 06:55 PM #4
Do you have any further questions then? The correct way to do this is with a CardLayout, which really shouldn't take long, but it's your call. The problem is that you're trying to set the content pane of a JPanel, which doesn't make sense. Do you have it figured out now?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-14-2011, 07:28 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Problems with a loop calling data from an ArrayList.
By moriarty in forum New To JavaReplies: 30Last Post: 03-28-2010, 02:00 AM -
Problems with calling a ProgressBar dialog in another class
By Allgorythm in forum New To JavaReplies: 1Last Post: 02-19-2010, 10:35 AM -
calling JPanel's JTextField from another JPanel class
By k2k in forum AWT / SwingReplies: 3Last Post: 04-20-2009, 11:31 PM -
Problems with readLine() and calling methods
By peachyco in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:44 AM -
JPanel Problems
By Riftwalker in forum AWT / SwingReplies: 6Last Post: 10-15-2007, 11:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks