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的啊。。

解决方案 »

  1.   


    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);
    }}
      

  2.   

    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);
    }}
      

  3.   

    JFrame是不会调用update方法的,你可以试试Jpanle