簡體   English   中英

Java JFrame & JPanel 與 Repaint() 的差異

[英]Java JFrame & JPanel Differences with Repaint()

我一直在玩一些簡單的Graphics2D繪畫,並從這里的社區獲得了一些非常好的幫助。

I managed to get the flickering resolved from my "bouncy balls" by moving the code away from the main JFrame class and into a JPanel which I then added to the JFrame class, can anyone tell me why this would make such a difference?

當您在 JComponent 的 paintComponent 方法(例如 JPanel 的)中繪制時,您使用 Swing,默認情況下在繪制時使用雙緩沖。 直接在 JFrame 的 paint 方法中繪圖將只允許 AWT 類型的繪圖,因為 JFrame 直接繼承自 Frame,一個重量級容器,並且由於 AWT 圖形默認不使用雙緩沖,這將導致 animation 不穩定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM