好的,我正在为我的学校项目开发 JApplet。我想要它做的是每次单击 JButton 时,“菜单按钮”,它会删除容器的当前内容,然后将新的 JApplet 添加到容器中。我有它的工作,我得到的唯一错误是它没有重新绘制容器的内容,但是如果我调整窗口(我目前正在使用 appletviewer 显示它)它将显示我想要的它显示。下面是我用于 actionPerformed 方法的代码示例...
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == word_guess)//JButton
{
WordGuess w = new WordGuess(); //Applet wanted to be displayed
c.remove(main);//removes current content of container
c.remove(side);
c.setLayout(new GridLayout(1,0)); //changes Layout
c.add(w);
w.init(); //calls the init method of WordGuess
repaint(); //I tried to see if repainting would help, and it didn't
}
}