removing and adding new JPanel to JApplet

Hello,
I am trying to make a game applet. When the JApplet goes to the second stage I remove the first JPanel from the JApplet's content pane and add the new one, but all I get is a gray box as if the new JPanel is not really being added.
Here is some of the code:

// clean up stuff from old stage
removeKeyListener( myKeyInputer );
getContentPane().remove( myOptionsView );
myOptionsModel.deleteObserver( this );

// make new stuff for color stage
myColorModel = new colorModel( players, this );
myColorView = new colorView(
myColorModel, extractParam("WIDTH"), extractParam("HEIGHT") );
myColorModel.addObserver( this );
getContentPane().add( myColorView );
myKeyInputer = new colorInputer( this, myColorModel );
addKeyListener( myKeyInputer );
myColorModel.run();

Is there something obvious I'm missing or would anyone look at the whole thing?

Comments

  • Have you tried
    a) repaint ()
    b) revalidate ()
    ?

    I think it might be something like that missing.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Thanks I was repainting the old view in my update method, but I changed it and repaint didn't change anything, but I added revalidate and it does.

    : Have you tried
    : a) repaint ()
    : b) revalidate ()
    : ?
    :
    : I think it might be something like that missing.
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :
    :

  • : ...I added revalidate and it does.

    Yes, that one is easy to forget somethimes. It tells the componenets to check wheter thay are visible or hidden behind something. I use to forget this myself every now and then. Mucho irritado and kicko the machino :-).



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories