现面这段代码有两个方法,分别为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);
}
}
在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);
}
}
解决方案 »
- 各位过来人给个意见,SE部分看完了,是巩固呢,还是继续EE部分,回头再巩固SE?
- Java中的comparator 怎么使用Collections.max()求出最大值?
- scjp考证试题
- 问问
- 关于try,catch有一点不明
- 新手提问
- 求助:关于在jtree中得到结点的名称
- 数组求最大直 怎么错了???
- 新手求概念:封装良好,松耦合,高聚合
- ender(ender) ( ) ,……等大侠请进!中文问题要事!!请大家帮忙解决!!
- 请问: public class JLabel extends JComponent implements SwingConstants,Accessible分别是什么意思呀
- 初学JAva,编了一个小程序,请问牛人,那里错了?
你把paint改成你该paint1 就不会了