Howdy, Stranger!

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

Categories

removing and adding new JPanel to JApplet

dontknow82dontknow82 Member Posts: 11
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

  • chamsterchamster Member Posts: 662
    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

  • dontknow82dontknow82 Member Posts: 11
    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
    :
    :

  • chamsterchamster Member Posts: 662
    : ...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

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    _______ | http://forcoder.org | free ebooks and video tutorials about [ Swift, PL/SQL, Delphi, Objective-C, Ruby, C#, Go, Visual Basic .NET, C, Perl, Visual Basic, Python, Scratch, PHP, MATLAB, R, C++, Assembly, JavaScript, Java LabVIEW, Ada, ABAP, Transact-SQL, Scala, Kotlin, D, Erlang, VBScript, Fortran, ML, Lua, COBOL, F#, Dart, Julia, Scheme, SAS, FoxPro, Prolog, Awk, Alice, Lisp, Bash, Logo, Rust, Hack, Crystal, Apex, Clojure ] ___________

Sign In or Register to comment.