package aufgaben.blatt1; import java.awt.Color; import java.awt.Graphics; import java.awt.Polygon; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import aufgaben.Aufgabe; import misc.Utils; public class Aufgabe2b40 extends Aufgabe { private final int width = 500, height = 500; private boolean done = false; private String name; public Aufgabe2b40() { name = "Blatt 1 - 2b40"; this.setSize(width, height); this.setTitle("Blatt 1 - Aufgabe 2b - 40 Objekte"); this.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("close"); done = true; } } ); } @Override public boolean done() { return done; } public void paint(Graphics g) { int x, y; for(int i = 0; i<40; i++) { x = Utils.randomInt(0, width); y = Utils.randomInt(0, height); switch(Utils.randomInt(0, 8)) { case 0: g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y)); break; case 1: g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y)); break; case 2: g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360)); break; case 3: g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360)); break; case 4: g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y)); break; case 5: g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y)); break; case 6: g.drawPolygon(getPolygon()); break; case 7: g.fillPolygon(getPolygon()); break; case 8: g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height)); break; } g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255))); } } private Polygon getPolygon() { int bla = Utils.randomInt(1, 100); int[] x = new int[bla], y = new int[bla]; for(int i = 0; i