In my applet I make use of different BufferedImages and use them as screen parts. Each screen part will only be repainted when the content needs to change.
This is the abstract ScreenPart class:
public abstract class ScreenPart extends BufferedImage{
Graphics2D g;
private BufferedImage buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
public ScreenPart(int width, int height) {
super(width, height, BufferedImage.TYPE_INT_ARGB);
g = createGraphics();
repaint();
}
public abstract void paint(Graphics2D g);
public void repaint(){
g.drawImage(buffer, 0, 0, null);
paint(g);
}
}
But the buffer doesn’t work because the buffer is also transparent. It will work when I change the BufferedImage type of the buffer from ARGB to RGB but this displays also a black background. So my question is: how can I correctly repaint this BufferedImage with a buffer?
Already found a solution:
This doesn’t make use of another
BufferedImage.