Tag: flicker

如何消除动画期间出现的闪烁?

我正在通过在JApplet中制作一个小游戏来学习Java。 我的精灵动画有点问题。 这是代码: this.sprite.setBounds(0,0,20,17); this.sprite.setIcon(this.rangerDown); for(int i = 0; i< 16;i++) { this.sprite.setBounds(this.sprite.getX(), this.sprite.getY()+1, 20, 17); this.sprite.update(this.sprite.getGraphics()); try{ Thread.currentThread().sleep(100); }catch(InterruptedException e){ } } 它在动画期间留下了一些闪烁。 一旦动画结束,闪烁就消失了,但它有点难看……我想我错过了一些步骤。 我使用这种方法是因为它现在提供了更好的结果,但是如果可能的话我想保持不使用AWT,而是使用Swing。 任何想法如何摆脱闪烁? 谢谢阅读。 Screenshoot (无法发布图片,抱歉)。

更新时摇摆组件闪烁很多

我在某处有几千行代码,我注意到当我更新它时,我的JTextPane闪烁了……我在这里写了一个简化版本: import java.awt.*; import javax.swing.*; public class Test { static JFrame f; static JTextPane a; static final String NL = “\n”; public static void main(String… args) { EventQueue.invokeLater(new Runnable(){ public void run() { f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); f.setSize(400, 300); f.setLocationRelativeTo(null); a = new JTextPane(); f.add(new JScrollPane(a)); new Thread(new Runnable(){ public void run() { […]

防止Java在更新时重新绘制JPanel的内容

我有一个包含很多子组件的JPanel。 在更新\添加新组件到父JPanel时,我想阻止它重新绘制,这怎么能实现?

JApplet – super.paint(); 导致闪烁

我现在正在写一个JApplet,每当我调用super.paint()时,applet都会闪烁。 我正在使用双缓冲(绘制到图像,然后渲染该图像),但我认为super.paint()正在清除屏幕或其他东西,击败我的双缓冲区。 我知道我应该使用paintComponents(),但出于某种原因,当我调用“currentScreen.Draw(g)”时,它不会显示屏幕的绘制。 谁能帮我这个? public void paint(Graphics g) { super.paint(g);//Remove this and it works, but the JApplet background color will be gone, and everything will be white. currentScreen.Draw(g); } 画面绘制方法 public void Draw(Graphics g) { if(buffer != null) g.drawImage(buffer, 150, 0, null); //g.drawString(drawstring, x, y); }