2012-04-22 65 views
2

我實現的移動文本報價器移動不平穩,並且平行執行重型GUI操作時,問題更嚴重。
我使用手動雙緩衝創建自己的圖像,將繪。
在數據變化,我用下面的代碼更新我的緩衝圖像:文字報道器移動不順暢

public static BufferedImage createBufferedImage(int w, int h) { 
     GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 
     GraphicsDevice gs = ge.getDefaultScreenDevice(); 
     GraphicsConfiguration gc = gs.getDefaultConfiguration(); 
     return gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT); 
    } 

然後我得出使用的drawText(..)就可以了所需的文本,之後調用重繪()。

並行地,每10毫秒一個異步線程計算圖像的下一個X位置,然後調用repaint()。

我的主要部件延伸JComponet,並覆蓋的paintComponent(),如下所述:

@Override 
    protected void paintComponent(Graphics g) { 
     super.paintComponent(g); 
     g.drawImage(baseImage, scrollTextX, 0, null); 
    } 

是否有任何技巧,使運動更好嗎?
如何讓股票行情不受其他圖形用戶界面操作的影響?

+0

爲了更快提供更好的幫助,請發佈[SSCCE](http://sscce.org/)。 – 2012-04-22 10:01:37

回答

0

我猜這是在Swing應用程序中使用?然後我認爲你應該從AWT事件派發線程更新UI。您可以使用SwingUtilities類中的invokeLater方法執行此操作。