Buttons not appearing in applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shisou
    New Member
    • Jul 2007
    • 52

    #1

    Buttons not appearing in applet

    Hey Guys,

    I'm currently writing a java applet for my class and I've run into a quirky little problem. I assure you answering this won't be considered cheating in anyway since it's just a bug and not the solution to the assignment.

    I have 5 buttons that I need to use at different times in the applet. initially I need to have two on the screen (buttons B1 and B2). so in my init() I have these two added to the applet. Then once either of these buttons is pressed it should remove them and place three other buttons (B3, B4, B5). so in my event() I have it handle the click by this.remove() B1 and B2 then this.add() B3-B5. Then I change a variable and call repaint() since there are other changes on the applet depending on the button pressed. Unfortunately buttons B3-B5 don't appear on the applet, the repaint() happens but the buttons are strangely missing.

    Is there something else I have to do to assure that my buttons get added properly?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Call the validate() and repaint() methods on the applet after removing the old and adding your new buttons.

    kind regards,

    Jos

    Comment

    • Shisou
      New Member
      • Jul 2007
      • 52

      #3
      I had a feeling it would be something easy that I just never heard of before!

      Thanks a million!

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Shisou
        I had a feeling it would be something easy that I just never heard of before!

        Thanks a million!
        You're welcome; it really pays back to read Sun's Swing tutorial (sorry no link here) and really understand what's happening underneath the surface.

        kind regards,

        Jos

        Comment

        Working...