重新绘制方法时JFrame闪烁的问题

时间:2016-01-16 15:26:13

标签: java swing

所以我在多个地方读过你不应该直接在JFrame上绘制的内容。有人可以更具体地说明如何做到这一点。所以,如果我有这样的课程。我的目标是尽量减少闪烁并利用双缓冲。

    public class GameFrame extends JFrame{
    public GameFrame(){
    super("FOOBAR");
    this.setSize(480,480);
    this.repaint();
    }
    public static void main(String[] a){
    //what is a better way of doing this
    GameFrame g=new GameFrame();
    while(true){
    g.repaint();
    }
    }
    public void paint(Graphics g){
    //I am not supposed to this
    g.clearRect(0,0,480,480);
    /**implementation not shown*/
    }
    }

0 个答案:

没有答案