这是问题所在。我有一个 JApplet,在 applet 内我有两个 JPanel,panel1 和 panel2。每个面板都有一个显示为“panel1”或“panel2”的标签,每个面板都有一个名为“switch”的按钮。当我运行小程序时,我只希望 panel1 可见。当我单击切换按钮时,我希望 panel1 不可见(或消失),而 panel2 可见。我还想单击 panel2 中的切换按钮以切换回 panel1。谁能帮我这个?
public class MyApplet extends JApplet
{
private Panel1 panel1;
private Panel2 panel2;
public void init()
{
setLayout(new FlowLayout());
panel1 = new Panel1();
panel2 = new Panel2();
add(panel1);
//add(panel2);
}
}
public class Panel1 extends JPanel
{
private JLabel label;
private JButton button;
public Panel1()
{
setLayout(new FlowLayout());
label = new JLabel("Panel1");
button = new JButton("Switch1");
add(label);
add(button);
}
}
public class Panel2 extends JPanel
{
private JLabel label;
private JButton button;
public Panel2()
{
setLayout(new FlowLayout());
label = new JLabel("Panel2");
button = new JButton("Switch2");
add(label);
add(button);
}
}