Strange Panel behavior

Well, I am making a game of Deal or No Deal for my Computer Science class, and I have run into what appears to be a random bug in the code or something. I have 5 Panels, with 6 cases on the first four and 2 on the bottom panel. The cases are buttons which send to an action performed, if it is the first click, it runs it through a little series, as such:

{

int i=Integer.parseInt(evt.getActionCommand());

//This part just sets the number aside for later, to be called up at the end of the game

game.makeTheChosenOne(evt.getActionCommand());

//This is the slacker way I have of removing the case no matter what panel is clicked

cp.remove(theCase);

Panel1.remove(theCase);

Panel2.remove(theCase);

Panel3.remove(theCase);

Panel4.remove(theCase);

Panel5.remove(theCase);

PanelAll.remove(theCase);

/*0,6,12,18,24*/

//The println just lets me see what array index is used

System.out.println(i);

// This should replace a black image with the case that is first clicked

caseLabel.add(theCase);

//Panels 1-5

Panel1.repaint();

Panel2.repaint();

Panel3.repaint();

Panel4.repaint();

Panel5.repaint();

//Main Panel they sit on

PanelAll.repaint();

//This is where the Cases SHOULD show up

caseLabel.repaint();

// cp= Container for ContentPane

cp.repaint();

}

Now, in the code, you can see the /*0,6,12,18,24*/ comment, I put this in here, because for some reason, those are the only index's that actually output the case image to caseLabel. For the first click, all of them should. The remove case part works flawlessly, but for some reason, only the first case on every Panel works when outputting it to the Panel.

incase you can't imaging it...(the index is in parentheses, case number is bold

1(0)2(1)3(2)4(3)5(4)6(5)

7[/b(6)8(7)9(8)10(9)11(10)12(11)

13[/b(12)14(13)15(14)16(15)17(16)18(17)

19[/b(18)20(19)21(20)22(21)23(22)24(23)

25[/b(24)26(25)

Only the first one in every set works correctly.

[2386 byte] By [bizkuta] at [2007-11-27 1:49:33]
# 1

//This is the slacker way I have of removing the case no matter what panel is clicked

cp.remove(theCase);

Panel1.remove(theCase);

Panel2.remove(theCase);

Panel3.remove(theCase);

Panel4.remove(theCase);

Panel5.remove(theCase);

PanelAll.remove(theCase);

Don't do it "the slacker" way. You can find out which panel to remove if from like this.

int panelNum = (caseIndex / 6) + 1;

Also, I think that calling repaint() on the top-level container will also paint all child-containers. I don't know if these will fix your problem because I didn't really look through your code. Repost it between [code]...[/code] tags, it makes it much easier to read.

CaptainMorgan08a at 2007-7-12 1:14:59 > top of Java-index,Java Essentials,Java Programming...
# 2
Didn't take much time trying to understand the questions with unformatted code, but in general, when adding or removing components from a visible GUI you need to invoke the revalidate() method on the panel in order to invoke the LayoutManager and repaint the panel correctly.
camickra at 2007-7-12 1:15:00 > top of Java-index,Java Essentials,Java Programming...