我意识到这段代码看起来毫无意义,我刚刚摆脱了不相关的东西来显示结构
class Drawer extends JComponent {
public Drawer(int[] data) {
System.out.println("drawer");
for(int x = 0; x < data.length; x++){}
//work out what to draw
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println("drawerpC"); //check to see if it is called
//draw stuff
}
}
在单独的文件中,Drawer
定期调用 的新实例。每次调用data
都是不同的,所以每次Drawer
调用都paintComponent
需要调用。
我在另一个文件中有这段代码:
Drawer d = new Drawer(data);
myGUI.con.add(d); //myGUI.con is a previously set up container
repaint()
不会导致paintComponent
被调用(否则你会看到标准输出),那么我如何强制paintComponent
每次调用都被调用Drawer
?