boid/Display.java
2020-06-27 16:19:15 +02:00

37 lines
990 B
Java

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) {
// Doppelpuffer um Flackern zu verhindern
BufferedImage b = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics bg = b.getGraphics();
bg.setColor(Color.BLACK);
bg.fillRect(0, 0, width, height);
bg.setColor(Color.WHITE);
for (Drawable d : dc.get_drawables()) {
d.draw(bg);
}
g.drawImage(b,0, 0, width, height, Color.BLACK, this);
}
}