JFrame的子类调用repaint方法 有关问题

aftermisak 2013-04-16 08:52:22
import java.awt.Graphics;

import javax.swing.JFrame;

public class Test extends JFrame
{
public Test()
{
this.setBounds(0, 0, 500, 500);
new Thread( new Runnable()
{
@Override
public void run()
{
while(true)
{
Test.this.repaint();
System.out.println("call repaint");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
@Override
public void paint(Graphics g)
{
super.paint(g);
System.out.println("call paint");
}
@Override
public void update(Graphics g)
{
System.out.println("call update");
}

public static void main(String[] args)
{
new Test().setVisible(true);
}

}
这个程序 重写了, update 和paint 起了一个线程每100毫秒掉一次repaint,但是根据输出显示..每次调用repaint 接下来调用的是paint,怎么没掉update啊.. update的原型是这样的吧。。我之前听说应该是先调用update的啊。。
...全文
112 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
张某码 2013-04-16
  • 打赏
  • 举报
回复
JFrame是不会调用update方法的,你可以试试Jpanle
aftermisak 2013-04-16
  • 打赏
  • 举报
回复
aftermisak 2013-04-16
  • 打赏
  • 举报
回复
import java.awt.Graphics; import javax.swing.JFrame; public class Test extends JFrame { public Test() { this.setBounds(0, 0, 500, 500); new Thread( new Runnable() { @Override public void run() { while(true) { Test.this.repaint(); System.out.println("call repaint"); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }).start(); } @Override public void paint(Graphics g) { super.paint(g); System.out.println("call paint"); } @Override public void update(Graphics g) { System.out.println("call update"); } public static void main(String[] args) { new Test().setVisible(true); } }
aftermisak 2013-04-16
  • 打赏
  • 举报
回复
import java.awt.Graphics; import javax.swing.JFrame; public class Test extends JFrame { public Test() { this.setBounds(0, 0, 500, 500); new Thread( new Runnable() { @Override public void run() { while(true) { Test.this.repaint(); System.out.println("call repaint"); try { Thread.sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }).start(); } @Override public void paint(Graphics g) { super.paint(g); System.out.println("call paint"); } @Override public void update(Graphics g) { System.out.println("call update"); } public static void main(String[] args) { new Test().setVisible(true); } }

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧