Results 1 to 3 of 3
  1. #1
    IndiDev is offline random developer
    Join Date
    Jan 2012
    Rep Power

    Question 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))){

    //start game button
    case 0: Game g = new Game();


    //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.

    for (int k = 0;k < 3;k++){
    JLabel l2 = new JLabel(new ImageIcon("OptF.png"));
    l2.setVisible(true); */


    //end game button
    case 2: System.exit(0);

    I came up with this idea when i looked at the constructor of my menu where i wrote
    to add the whole stuff of JLabel l1 to my Container c
    so i tried to replace the variables in the Listener like this
    But I get this error while compiling the program. error: cannot find symbol
    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.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: Replacing Containers?

    Sounds like a job for CardLayout.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    IndiDev is offline random developer
    Join Date
    Jan 2012
    Rep Power

    Default Re: Replacing Containers?

    thx a lot, that's what i needed!

Similar Threads

  1. Servlet commnication across 2 different containers
    By RaviLella in forum Java Servlet
    Replies: 1
    Last Post: 01-23-2012, 12:05 PM
  2. Components as containers
    By wired-in=p in forum AWT / Swing
    Replies: 8
    Last Post: 09-12-2011, 03:19 AM
  3. Replies: 14
    Last Post: 08-22-2011, 12:14 AM
  4. transparant containers
    By Dipke in forum New To Java
    Replies: 5
    Last Post: 03-27-2011, 02:41 PM
  5. Swing containers
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-07-2007, 12:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts