Results 1 to 3 of 3
Thread: Replacing Containers?
- 01-24-2012, 05:24 PM #1
random developer
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Replacing Containers?
Hello Community,
I'm developing a little game and i got stuck at the part where im trying to replace the content of the start menue with the content of the options menue. I don't want it to open a new Window after clicking the "Options"-Button in the Start menue. I tried to replace the container of the start menue with the container of the Options class by using getters but it won't work. I shortened the program for purpose of questioning.
//Listener Class of the menue class
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class MenueListener implements ActionListener{
Menue m;
Options o;
public MenueListener(Menue me, Options op){
m = me;
o = op;
}
public void actionPerformed(ActionEvent ae){
Object ob = ae.getSource();
for ( int j = 0;j< 3;j++){
if (ob.equals(m.getBtnOp(j))){
switch(j){
//start game button
case 0: Game g = new Game();
break;
//options button
case 1: //before trying the container replacing i tried to make every single element invisible
// and add new stuff to the container, but then i thought there must be an easier way, so i tried container replacing.
/*m.getL1().setVisible(false);
for (int k = 0;k < 3;k++){
m.getBtnOp(k).setVisible(false);
}
JLabel l2 = new JLabel(new ImageIcon("OptF.png"));
l2.setBounds(0,0,515,555);
m.getC().add(l2);
l2.setVisible(true); */
o.getC.add(m.getL1());
break;
//end game button
case 2: System.exit(0);
break;
}
}
}
}
}
I came up with this idea when i looked at the constructor of my menu where i wrote
c.add(l1);
to add the whole stuff of JLabel l1 to my Container c
so i tried to replace the variables in the Listener like this
o.getC.add(m.getL1());
But I get this error while compiling the program.
MenueListener.java:31:41: error: cannot find symbol
o.getC.add(m.getL1());
^
symbol: variable getC
location: variable o of type Optionen
I would be a big help if someone could give me a hint or another idea of replacing Frame content by button clicking.
- 01-24-2012, 05:33 PM #2
Re: Replacing Containers?
Sounds like a job for CardLayout.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-24-2012, 05:50 PM #3
random developer
- Join Date
- Jan 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Servlet commnication across 2 different containers
By RaviLella in forum Java ServletReplies: 1Last Post: 01-23-2012, 12:05 PM -
Components as containers
By wired-in=p in forum AWT / SwingReplies: 8Last Post: 09-12-2011, 03:19 AM -
Can't I add containers into containers? What's wrong here?
By Josep_16 in forum Java AppletsReplies: 14Last Post: 08-22-2011, 12:14 AM -
transparant containers
By Dipke in forum New To JavaReplies: 5Last Post: 03-27-2011, 02:41 PM -
Swing containers
By Java Tip in forum Java TipReplies: 0Last Post: 12-07-2007, 12:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks