2020-06-27 15:44:16 +02:00
|
|
|
import java.awt.Color;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
|
|
|
|
public class Display extends JFrame {
|
|
|
|
private static final long serialVersionUID = 8274011568777903027L;
|
|
|
|
private int width;
|
|
|
|
private int height;
|
|
|
|
private DrawableCollection dc;
|
|
|
|
|
|
|
|
public Display(int width, int height, DrawableCollection dc) {
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.dc = dc;
|
|
|
|
this.setSize(width, height);
|
|
|
|
this.setVisible(true);
|
|
|
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void paint(Graphics g) {
|
2020-06-27 16:19:15 +02:00
|
|
|
// Doppelpuffer um Flackern zu verhindern
|
2020-06-27 15:44:16 +02:00
|
|
|
BufferedImage b = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
|
|
|
Graphics bg = b.getGraphics();
|
2020-06-27 16:19:15 +02:00
|
|
|
|
2020-06-27 15:44:16 +02:00
|
|
|
bg.setColor(Color.BLACK);
|
|
|
|
bg.fillRect(0, 0, width, height);
|
|
|
|
bg.setColor(Color.WHITE);
|
|
|
|
for (Drawable d : dc.get_drawables()) {
|
|
|
|
d.draw(bg);
|
|
|
|
}
|
2020-06-27 16:19:15 +02:00
|
|
|
|
2020-06-27 15:44:16 +02:00
|
|
|
g.drawImage(b,0, 0, width, height, Color.BLACK, this);
|
|
|
|
}
|
|
|
|
}
|