repaint()方法调用了public void paint(Graphics g),所以打印paint(Graphics g),但是没有调用到public void update(Graphics g)这个方法。
解决方案 »
- java显示问题求教
- 各位帮着看一段怪异的代码(只有几行,但写法怪异).是servlet的源码里的.
- sun.jdbc.odbc.JdbcOdbcDriver is Sun proprietary API and may be removed in a future release
- Websphere、Weblogic,JBoss 那一种平台入门最快?
- 关于软件保护的问题
- 如何编译*.exe文件?
- 为什么这个程序用array.length()不成功?
- 非典被闹得这么严重,公司死活不放假,我该怎么办??是不是抗议!
- 鼠标事件,请帮忙
- 如何用Java设置系统时间?
- 请问有friendly,和private protected 这两种访问权限吗 ?
- 读取违反顺序?????从没遇见过
具体说明一下;
我用g.drawString("Hello " + System.currentTimeMillis(),20,20);
也不执行update
The AWT calls the update method in response to a call to repaint. The appearance of the component on the screen has not changed since the last call to update or paint. You can assume that the background is not cleared改为
public static void main(String[] args) {
MainClass mainClass = new MainClass();
mainClass.showFrame();
mainClass.repaint();
}即可
不过paint就不是很清楚了
public void paint(Graphics g){
//add this line
super.paint(g);
System.out.println("paint(Graphics g)");
drawString(g);
}
Thread t = null;
public MyComponent() {
super("fff");
....result will be
update()
run()
....As you overrided update() ( which usually will call paint()), paint() is not called by update(). So when paint() will be excuted is determined by JVM.
你的MyComponent是Component的派生类。J2sdk1.1后,Component的派生类都是轻量级(Lightweighted)的。Lightweighted 对象的repaint()会尽快调用paint()方法,而不是update()方法。这就是你的程序中update()不执行的原因。
Lightweighted不执行update()的目的是为了减少闪烁。
Component类中已经定义的大多数类是重量级的,包括Button,List,Label等。Heavyweighted对象的repaint()方法会产生一个PaintEvent事件并建议程序执行update()。实际什么时间执行update()是由程序决定的,并不由你控制。
如果你的MyComponent从重量级类派生的,你将会看到update()被执行。
如果frame add two Component,,
一个repaint(),另一个为什么也跟着repaint();