Question for the Java peeps

Status
Not open for further replies.
Writing a small Swing Applet,

Has two panels, one at the bottom with a 'back' and 'next' button and a main panel above the bottom panel which has various checkboxes on it for the user to input the answer to questions.

What I want is when the next button is pressed all the checkboxes dissapear and a new question is asked and new checkboxes drawn.

So basically I want the applet to cycle through 10 or so questions to the user then display results on a final page.

I thought the way to do it would be to create 10 different panels (panes?) with all the controls added to them, then remove the previous / add next panel when the button is clicked.

Problem is when the button is clicked it will not remove the previous panel:


public void actionPerformed(ActionEvent e)
{

getContentPane().remove(mainPanel);

}

If I put the 'getContentPane().remove(mainPanel);' line under the 'public void init()' of the applet it works fine, I just can't get it to remove a panel when a button is clicked. Do I need the update() function, if so what argument does it take, I can't figure it out.


Many thanks

Dom.
 

McMillan Y-4

Ars Scholae Palatinae
836
peeps?!?

Anyway, the case calls for... no, it screams for use of CardLayout.
What you do is you set the panel layout to be CardLayout, design each question to be a separate component, add them to the panel's layout with appropriate unique names (say, String-ified numbers between 0 and 9), and then you call the panel's layout 'show(<name> )' method to flip through them.

- Roberto
 
Status
Not open for further replies.