2013-05-11 28 views
1

系統規範和代碼示例在本文稿的最後!在安裝ubuntu 12.04後eclipse中的Jumpy動畫詳細(來自askubuntu.com的x-post)

首先,我是這個論壇的新手。請告訴我,如果佈局或問題本身有什麼問題。我也是新來的Linux,Ubuntu和Java的新手。我在Ubuntu之前使用了Windows 7。在我的機器上安裝ubuntu後,問題首先出現。

問題

當蝕運行的動畫窗口,使用擺動包或Java小程序 - 動畫跳動和不光滑。我會告訴你一個簡單程序的代碼示例,它由JPanel和帶有背景的JFrame以及從左到右移動的2d球組成。該程序設置爲每30 ms重新繪製一次。像這樣運行簡單的圖形應該不成問題。 Eclipse以其他方式快速平滑。希望任何幫助或建議,如果有人遇到過這樣的事情!

編輯:

添加例外:當我和我的鼠標懸停(和保持運動的話)在應用程序窗口的動畫停止beeing緊張。當我停止移動時,它開始變得不平穩,再次跳動。任何人都聽說過這個?

我試圖

*搜索有關該錯誤或問題,但沒有發現任何

*安裝Eclipse的最新版本和最新的JDK

*編輯我的日食.ini文件

*在我的Windows 7機器上運行我的代碼(工作正常)

*安裝熊蜂,並使用NVIDIA的Optimus

系統

OS:Ubuntu的12.04(精確)64位

內存:5.6吉布,處理器Intel Core 2.5GHz的×4 CPU

Eclipse Juno 4.2.0

java -version帶給我

$ -java version 
java version "1.7.0_21" 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11) 
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode) 

lspci | grep的VGA帶給我

00:02:0 VGA compatible controller: Intel Corporation Ivy Bridge Graphics Controller (rev 09) 

我eclipse.ini文件

-startup 
plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar 
--launcher.library 
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120913-144807 
-product 
org.eclipse.epp.package.jee.product 
--launcher.defaultAction 
openFile 
-showsplash 
org.eclipse.platform 
--launcher.XXMaxPermSize 
256m 
--launcher.defaultAction 
openFile 
-vmargs 

-Xincgc 

-XX:NewSize=8m 
-XX:MaxPermHeapExpansion=10m 
-XX:CMSInitiatingOccupancyFraction=70 
-XX:+UseCMSInitiatingOccupancyOnly 
-XX:+UseParNewGC 
-XX:+CMSConcurrentMTEnabled 
-XX:ConcGCThreads=2 
-XX:ParallelGCThreads=2 
-XX:CMSIncrementalDutyCycleMin=0 
-XX:CMSIncrementalDutyCycle=5 
-XX:GCTimeRatio=49 
-XX:MaxGCPauseMillis=20 
-XX:GCPauseIntervalMillis=1000 
-XX:+UseCMSCompactAtFullCollection 
-XX:+CMSClassUnloadingEnabled 
-XX:+DoEscapeAnalysis 
-XX:+UseCompressedOops 
-XX:+AggressiveOpts 
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses 

-Dosgi.requiredJavaVersion=1.7 
-Dhelp.lucene.tokenizer=standard 
-XX:MaxPermSize=128m 
-XX:PermSize=128m 
-Xmn128m 
-Xms1024m 
-Xmx1024m 
-Xss2m 
-XX:+UseConcMarkSweepGC 

代碼示例

/////////Sample from the JPanel class (extends JPanel)///////// 
private int y = 200; 
private int x = 0; 

public testPanel() { 
    setVisible(true); 
    setPreferredSize(new Dimension(1500, 400)); 
    setBackground(Color.black); 
} 

public void move() { 
    x = x + 2; 
} 

public void paintComponent(Graphics g) { 
    super.paintComponent(g); 
    g.setColor(Color.green); 
    g.fillOval(x, y, 50, 50); 
} 
} 

///////Sample from the JFrame class (extends JFrame)///////// 

private testPanel thePanel = new testPanel(); 
private Timer t = new Timer(30, this); 



public testFrame() { 
    add(thePanel); 
    setVisible(true); 
    setDefaultCloseOperation(EXIT_ON_CLOSE); 
    pack(); 
    t.start(); 

} 

public void actionPerformed(ActionEvent e) { 
    thePanel.move(); 
    repaint(); 
} 
+0

我假設パ從JPanel的延伸,並從testFrame JFrame的 – MadProgrammer 2013-05-11 08:40:10

+0

正確的延伸,將添加 – lsund 2013-05-11 08:43:34

回答

1

這不是一個回答每說 - 只是一堆意見...

我一直在Mac OSX上玩弄這個,我注意到它開始時會出現一個口吃,但在球反彈之前它會平滑下來。

這可能與JIT優化有關,甚至可能在系統穩定時進行GC交互。

嘗試的代碼讓我知道,如果它gitters更多然後2-3個療程(球會反彈)

import java.awt.BorderLayout; 
import java.awt.Color; 
import java.awt.Dimension; 
import java.awt.EventQueue; 
import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.awt.RenderingHints; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.Timer; 
import javax.swing.UIManager; 
import javax.swing.UnsupportedLookAndFeelException; 

public class SimpleAnimation { 

    public static void main(String[] args) { 
     new SimpleAnimation(); 
    } 

    public SimpleAnimation() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
       } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
       } 

       JFrame frame = new JFrame("Test"); 
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       frame.setLayout(new BorderLayout()); 
       frame.add(new TestPane()); 
       frame.pack(); 
       frame.setLocationRelativeTo(null); 
       frame.setVisible(true); 
      } 

     }); 
    } 

    public static class TestPane extends JPanel { 

     private int xPos = 0; 
     private int xDelta = 2; 
     protected static final int RADIUS = 40; 

     public TestPane() { 
      setBackground(Color.BLACK); 
      Timer timer = new Timer(40, new ActionListener() { 
       @Override 
       public void actionPerformed(ActionEvent e) { 
        xPos += xDelta; 
        if (xPos + RADIUS > getWidth()) { 
         xPos = getWidth() - RADIUS; 
         xDelta *= -1; 
        } else if (xPos < 0) { 
         xPos = 0; 
         xDelta *= -1; 
        } 
        repaint(); 
       } 

      }); 
      timer.setCoalesce(true); 
      timer.start(); 
     } 

     @Override 
     public Dimension getPreferredSize() { 
      return new Dimension(750, 400); 
     } 

     @Override 
     protected void paintComponent(Graphics g) { 
      super.paintComponent(g); 
      Graphics2D g2d = (Graphics2D) g.create(); 
      g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 
      g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); 
      g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); 
      g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); 
      g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 
      g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 
      g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); 

      int x = xPos; 
      int y = (getHeight() - RADIUS)/2; 
      g2d.setColor(Color.GREEN); 
      g2d.fillOval(x, y, RADIUS, RADIUS); 
      g2d.dispose(); 
     } 

    } 

} 
+0

hello mate!你的代碼一直在完美運行。 (也許有點閃光,但幾乎不明顯)。我無法真正看到你做了什麼來使它運行平穩,但我稍後會仔細研究它。謝謝 – lsund 2013-05-11 16:15:28

+0

+1'批量'RenderingHints';在Mac OS X上,對於[示例](https://sites.google.com/site/drjohnbmatthews/kineticmodel),請使用'Instruments.app'來查看更多內容。 – trashgod 2013-05-11 16:39:19

+0

@ user2315551:'JPanel'默認是雙緩衝。 – trashgod 2013-05-11 16:41:05