所以我創建了一個名爲BasePanel的抽象JPanel。在這裏面我我使用雙緩衝的代碼如下所示:擴展JPanel,得到了什麼
public void paint(Graphics g) {
dbImage = createImage(getWidth(), getHeight());
dbg = dbImage.getGraphics();
paintComponent(dbg);
g.drawImage(dbImage, 0, 0, this);
repaint();
}
public void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
}
然後又是面板上延伸時,我不知道將它仍然雙緩衝,如果我只是推翻了的paintComponent方法?所以,我wouldnt甚至需要調用paint方法
一個例子
public class StartScreen extends BasePanel {
@Override
public void paintComponent(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.WHITE);
g.drawString("Animation Screen", 175, 150);;
repaint();
}
}