[英]JApplet - super.paint(); causes flicker
我現在正在編寫一個 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);
}
不要使用繪畫,也不要直接在 JApplet 中繪制。 而是在 JPanel 的 paintComponent 方法中繪制並調用 super.paintComponent(g) 作為該方法的第一行。 將該 JPanel 添加到您的 JApplet 的 contentPane 以允許小程序顯示它。
編輯 1
此外,您不能為此使用 paintComponent ,因為它的作用完全不同。 再次使用paintComponent,但只能在從JComponent 派生的組件中使用,例如JPanel(或JComponent 本身)。
編輯 2還要始終在您的paintComponent 方法上方放置一個@Override,以確保您實際上覆蓋了超級方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.