本帖最后由 jimmili 于 2012-07-09 13:00:01 编辑

解决方案 »

  1.   

    有很多原因会导致控件重画,所以,不要"画完就忘",你需要在某个地方记住当前已经画过的所有东西:形状,位置等,并且记住它们的复盖关係,每次重画的时候从下往上依次重画当前所有的图形。另外,不要重写paint(),--重写paintComponent()。
      

  2.   

    把 paint() 方法中 第一句 super.paint() 注释掉 就不会重画了. 每次都在原有的内容上画新的
      

  3.   

    我写的画笑脸程序,只repaint(),不会覆盖掉,楼主参考下
    package SmileFace;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.Graphics;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class game extends JFrame{
    public JLabel jp = new JLabel("心随你动!!!");
    private int x = 0 , y = 0;

    public game(int x, int y, String title){
    this.x = x;
    this.y = y;
    jp.setBounds(100, 100, 100, 100);
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(jp);

    }

    public void lauchFrame() {
    this.setLocation(200, 100);
    this.setSize(500, 600);
    /*
     * 鼠標監聽的幾大分類 
     *  MouseListener, MouseMotionListener,
     *   MouseWheelListener, EventListener
     * 
     * MouseAdapter 对象实现 MouseListener 接口
     */
    addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e){
    jp.setLocation(e.getPoint());
    x = e.getX();
    y = e.getY();
    repaint();
    }
    });

    this.setVisible(true);
    }

    public void paint(Graphics g) {
    Color c = g.getColor();
    g.setColor(Color.BLACK);
    g.drawOval(x,  y, 60, 70);
    g.drawOval(15 + x, 15 + y, 10, 10);
    g.drawOval(35 + x, 15 + y, 10, 10);

    /*
     * 畫三角形的三步
     */
    int[] xPoints=new int[]{25 + x, 30 + x, 35 + x};//所有点的x坐标
    int nPoints = 3; //点数
    int[] yPoints=new int[]{35 + y, 40 + y, 35 + y};//所有点的y坐标
    g.drawPolygon(xPoints, yPoints, nPoints);
    g.drawOval(20 + x, 50 + y, 20, 10);
    g.setColor(c);
    }

    public static void main(String[] args) {
    /*
     * 新建game對象
     * 調用lauchFrame()方法  
     *  注意:窗口的實現在lauchFrame()裏面,笑臉的構造在類的構造方法裏面!
     * 
     */
    game gf = new game(0, 0, "SmileFace-Game");
    gf.lauchFrame(); }
    }