repaint()方法调用了public void paint(Graphics g),所以打印paint(Graphics g),但是没有调用到public void update(Graphics g)这个方法。

解决方案 »

  1.   

    我觉得程序中没有调用update这个方法,
      

  2.   

    update() 方法是当数据改变时才调用.
      

  3.   

    to onefox(一品狐);
    具体说明一下;
    我用g.drawString("Hello " + System.currentTimeMillis(),20,20);
    也不执行update
      

  4.   

    Updates this component. 
    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();
    }即可
      

  5.   

    update是调用的Component的
    不过paint就不是很清楚了
      

  6.   

    同意 binbin2000移动一下也可以看见!
      

  7.   

    http://expert.csdn.net/Expert/topic/2523/2523130.xml?temp=.629162 麻烦看看
      

  8.   

    我把窗体放大,最小化,移动……都不执行update,为什么?
      

  9.   

    程序改错:
    public void paint(Graphics g){
                      //add this line
                      super.paint(g);
    System.out.println("paint(Graphics g)");
    drawString(g);
    }
      

  10.   

    subclass extends java.awt.Component is Lightweighted component, while existing defined awt components (Button, List..) are Heavyweighted.If it's a lightweighted component, repaint() will try to call paint() as soon as possible, otherwise, repaint() will generate a PaintEvent which will suggest update() to be executed. Another thing is when to execute update() is determined by the Thread. It will be on the schedule, but you don't know when.
      

  11.   

    try this:class MyComponent extends Label implements Runnable {
    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.
      

  12.   

    还没明白?
    你的MyComponent是Component的派生类。J2sdk1.1后,Component的派生类都是轻量级(Lightweighted)的。Lightweighted 对象的repaint()会尽快调用paint()方法,而不是update()方法。这就是你的程序中update()不执行的原因。
    Lightweighted不执行update()的目的是为了减少闪烁。
    Component类中已经定义的大多数类是重量级的,包括Button,List,Label等。Heavyweighted对象的repaint()方法会产生一个PaintEvent事件并建议程序执行update()。实际什么时间执行update()是由程序决定的,并不由你控制。
    如果你的MyComponent从重量级类派生的,你将会看到update()被执行。
      

  13.   

    感谢wobelisk(),学到好东西了。
      

  14.   

    to wobelisk(),
    如果frame add two Component,,
    一个repaint(),另一个为什么也跟着repaint();
      

  15.   

    wobelisk()把我从书上看的知识解释的这么透彻,学习ING!~~~