MyException - 我的异常网
当前位置:我的异常网» J2SE » 各位大大,为啥小弟我画的圆有毛边,加了双缓冲还是

各位大大,为啥小弟我画的圆有毛边,加了双缓冲还是看见一闪一闪的

www.MyException.Cn  网友分享于:2013-12-29  浏览:7次
各位大大,为啥我画的圆有毛边,加了双缓冲还是看见一闪一闪的?
Java code

import java.awt.*;
import java.awt.event.*;
public class TankClient extends Frame {

    Image fim = null;
    int framex =30;
    int framey = 50;
    public void paint(Graphics g) {
        Color c = g.getColor();
        g.setColor(Color.RED);
        g.fillOval(framex, framey, 30, 30);
        g.setColor(c);
        framex+=5;
        framey+=5;
    }

    public void update(Graphics g) {
//System.out.println("调用了update");
        if(fim == null){
            fim = this.createImage(800, 600);
        }
        Graphics fimgs = fim.getGraphics();
        Color c = fimgs.getColor();
        fimgs.setColor(Color.GREEN);
        fimgs.fillRect(0, 0, 800, 600);
        paint(fimgs);

        g.drawImage(fim, 0, 0, null);
    }

    
    public TankClient(String s){
        super(s);
    }

    public void launchFrame(){
        
        this.setBounds(250, 200, 800, 600);
        this.setResizable(false);
        this.setBackground(Color.green);
        this.setVisible(true);
        
        this.addWindowListener(new WindowAdapter(){


            public void windowClosing(WindowEvent e) {
                e.getWindow().setVisible(false);
                System.exit(0);
            }
            
            public void windowClosed(WindowEvent e) {
                
                
            }
        });
        
        new Thread(new FrameRepaint()).start();
    }
    
    public class FrameRepaint implements Runnable{

        public void run()  {
            while(true){
                repaint();
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }        
    }

    
    public static void main(String [] args){
        TankClient tc = new TankClient("坦克世界");
        tc.launchFrame();
    }
    
    
    
}





------解决方案--------------------
if(g instanceof Graphics2D){
g = (Grahpics2D) g;
g.setRenderingHint(RenderingHints.KEY_ANTILASING,RenderingHints.VALUE_ANTIALIAS_ON);
}

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有