Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Graphics.clearRect()源代码';我不工作_Java_User Interface_Graphics - Fatal编程技术网

Java Graphics.clearRect()源代码';我不工作

Java Graphics.clearRect()源代码';我不工作,java,user-interface,graphics,Java,User Interface,Graphics,嗨,我在网上搜索了一段时间,但我遇到的解决方案对我来说并不适用。这就是我的问题: 我正在使用Graphics and drawLine()在GUI上绘制一些图形,这对我来说是第一次。当我告诉我的程序在同一区域上重新绘制另一个图形时,它只是把事情搞砸了 public void paintComponent(Graphics g) { super.paintComponent(g); int max = 100; g.clearRect(0,

嗨,我在网上搜索了一段时间,但我遇到的解决方案对我来说并不适用。这就是我的问题:

我正在使用Graphics and drawLine()在GUI上绘制一些图形,这对我来说是第一次。当我告诉我的程序在同一区域上重新绘制另一个图形时,它只是把事情搞砸了

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        int max = 100;
        g.clearRect(0, 0, 205, 200); <-- 

        g.drawRect(10, 10, 200, 200);
        g.drawString(""+max, 0, 10);
        g.drawLine(5, 110, 10, 110);
        g.drawString("0", 0, 275);

        ...Drawing the actual graph here...
    }
公共组件(图形g){
超级组件(g);
int max=100;

g、 clearRect(0,0,205,200);您确定设置了正确的背景色吗?我尝试了g.setColor(color.White)和g.fillRect(…)但遗憾的是,它也不起作用。您不需要每次都清除图形,它是默认情况下在Swing中实现的双缓冲过程的一部分。您最好以产生问题的方式稍微扩展此代码段,以便我们自己运行它。我会的,但如果我向您发送更多,我几乎需要发送一切都是为了让它工作。无论如何,我似乎可以通过在我的JPanel上手动调用repaint()来解决这个问题。不过谢谢你的帮助。