我的问题是,如何通过再次运行OtherPanel,使用动作侦听器清除图形并创建一组新图形?使用ActionListener从JPanel清除图形
public class MainFrame extends JFrame
{
private OtherPanel panel;
public MainFrame()
{
panel = new OtherPanel();
}
class OtherPanel extends JPanel
{
private OtherPanel()
{
...
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
....
}
private class ReloadListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
}
这看起来真的很微不足道。你有什么尝试?它以什么方式失败? – John3136 2012-03-19 02:09:54
我现在想通了。但我不知道为什么我需要updateUI(); – chief 2012-03-19 02:18:39
不要为此使用'updateUI()'; 'panel.repaint()'应该就足够了。如果不是,请编辑您的问题以包含一个[sscce](http://sscce.org/),其中包含您所描述的问题。 – trashgod 2012-03-19 04:26:10