Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.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中更新方法内未激活fillRect或drawImage_Java_Swing_Applet - Fatal编程技术网

java中更新方法内未激活fillRect或drawImage

java中更新方法内未激活fillRect或drawImage,java,swing,applet,Java,Swing,Applet,嗨,我一直在努力摆脱我在JFrame应用程序上的闪烁。我们已经四处搜索,发现setDoubleBuffered(true)可以用于Jpanel的paintComponent,但不能用于JFrame的paintMethod,也不能用于applet 通过在paint方法中引入this.createbufferstrategy(2)指令,以及在paint方法中引入this.setignorerepaint(true)指令,设法减少但不消除闪烁,并进一步减少闪烁 但我最终找到了一个完全消除闪烁的代码示例

嗨,我一直在努力摆脱我在JFrame应用程序上的闪烁。我们已经四处搜索,发现setDoubleBuffered(true)可以用于Jpanel的paintComponent,但不能用于JFrame的paintMethod,也不能用于applet

通过在paint方法中引入this.createbufferstrategy(2)指令,以及在paint方法中引入this.setignorerepaint(true)指令,设法减少但不消除闪烁,并进一步减少闪烁

但我最终找到了一个完全消除闪烁的代码示例,它通过在update函数中绘制静态元素来工作

在applet中测试了update中的fillRect,它可以工作,但是当复制粘贴到常规java应用程序中时,它在jframe的update函数中不起作用

这是密码

   Graphics graphics;
   Image image;
   public void update(Graphics g)
   {
   if (image == null) {  

   image = createImage(this.getWidth(), this.getHeight());

   graphics = image.getGraphics();  }

   graphics.setColor(Color.blue);

   graphics.fillRect(0,  0,  this.getWidth(),  this.getHeight());

   g.drawImage(image, 0, 0, this);//}
通过一个空的绘制功能,它将绘制到屏幕上,并在小程序中用蓝色填充,它还消除了闪烁。但在jframe的正常应用程序中,它什么也不做

在非小程序常规应用程序环境中,需要做什么才能允许fillRect或drawImage在更新中工作

顺便说一句,如果调用fillRect来修改图形对象本身,那么如何修改图像对象呢?因为drawImage是屏幕变蓝所必需的


PS我尝试过不同时使用createbufferedstrategy和setignorerepaint,但没有任何变化。

当使用
setIgnorePaint(true)
时,它不允许您弄乱图形。 我是通过update(Graphics g)参数的外观猜出来的,您在paint方法中调用它,使用paintMethod的Graphics g来绘制(inside paint方法,您调用update(g))

如果忽略绘制,它将不允许您使用绘制组件的图形参数。 发布所有包含图形的代码(在哪里制定策略,在哪里调用此方法,等等)


闪烁是该策略的一个相当主流的问题,我不能保证我能解决它(我的朋友不久前向我提出了这个问题,但我没有足够的兴趣去尝试和解决它),但这至少可以解释为什么您的图形没有渲染,为什么不使用JPanel来绘制…?我会在update方法中放置一个System.out以确保调用该方法?在绘制图像之前,我还会调用graphics.dispose…不要覆盖update()。这是用于AWT绘制的旧代码。Swing在默认情况下是双缓冲的,其中包括JFrame,因为它只使用JPanel作为内容窗格。问题出在您的代码中,因此您需要发布一个演示问题的
SSCCE