public void paint(Graphics g) {
super.paint(g);
        Color c = g.getColor();
        g.setColor(Color.RED);
        g.fillOval(x, y, 30, 30);
        g.setColor(c);
        
        y += 5;
    }这样呢? 44看哇

解决方案 »

  1.   

    JDk Component.class 中源代码
    public void repaint(long tm, int x, int y, int width, int height) {
            if (this.peer instanceof LightweightPeer) {
                // Needs to be translated to parent coordinates since
                // a parent native container provides the actual repaint
                // services.  Additionally, the request is restricted to
                // the bounds of the component.
                if (parent != null) {
                    int px = this.x + ((x < 0) ? 0 : x);
                    int py = this.y + ((y < 0) ? 0 : y);
                    int pwidth = (width > this.width) ? this.width : width;
                    int pheight = (height > this.height) ? this.height : height;
                    parent.repaint(tm, px, py, pwidth, pheight);
                }
            } else {
                if (isVisible() && (this.peer != null) &&
                    (width > 0) && (height > 0)) {
                    PaintEvent e = new PaintEvent(this, PaintEvent.UPDATE,
                                                  new Rectangle(x, y, width, height));
                    Toolkit.getEventQueue().postEvent(e);           
                }
            }
        }JFrame和Frame一个为轻量级、一个为重量级,轻量级的未完全重构