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

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

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

    Default 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!

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

    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, 01:05 PM
  2. Components as containers
    By wired-in=p in forum AWT / Swing
    Replies: 8
    Last Post: 09-12-2011, 04:19 AM
  3. Replies: 14
    Last Post: 08-22-2011, 01:14 AM
  4. transparant containers
    By Dipke in forum New To Java
    Replies: 5
    Last Post: 03-27-2011, 03:41 PM
  5. Swing containers
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-07-2007, 01: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
  •