现面这段代码有两个方法,分别为lunchFrame()和paint()方法。
在main方法中只调用了lunchFrame,而paint这个方法为什么也会执行?
如果不调用lunchFrame这个方法就不行?我以看看书上说的是,方法只有调用才能在内存中分配空间从而执行。为什么这个paint方法没有调用也会在面板上画出个圆?import java.awt.*;
import java.awt.event.*;public class TankClient extends Frame {
public static void main(String[] args) {
TankClient tc = new TankClient();
tc.lunchFrame();
}
public void paint(Graphics g)  {
Color c = g.getColor();
g.setColor(Color.red);
g.fillOval(50, 50, 30, 30);
g.setColor(c);
}
public void lunchFrame() {
this.setLocation(200, 200);
this.setSize(800, 600);
this.setTitle("坦克大战");
this.setResizable(false);
this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBackground(Color.green);
this.setVisible(true);
}
}