日期:2014-05-20  浏览次数:20708 次

新手问题 关于main 方法调用的疑问!!!!
现面这段代码有两个方法,分别为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);
}
}

------解决方案--------------------
paint 方法是 Jframe初始化时候自动调用的
你把paint改成你该paint1 就不会了
------解决方案--------------------
很可惜,楼主的想法失败鸟。paint 被调用鸟。
------解决方案--------------------
paint is called by system