C
chipper
Gast
Java:
public void paint(Graphics g)
{
Graphics2D g2d= (Graphics2D) g;
int breite = getWidth();
int hoehe = getHeight();
int rot, gruen, blau;
Color farbe;
int x1, y1, r_breite, r_hoehe;
for ( int i = 1; i <= 5; i++ )
{
rot = (int) (Math.random() * 255);
gruen = (int) (Math.random() * 255);
blau = (int) (Math.random() * 255);
farbe = new Color ( rot, gruen, blau );
g2d.setColor(farbe);
x1 = (int) (Math.random() * breite);
y1 = (int) (Math.random() * hoehe);
r_breite = (int) (breite - x1 - Math.random() * breite);
r_hoehe = (int) (hoehe - y1 - Math.random() * hoehe);
g2d.drawRect(x1, y1, r_breite, r_hoehe );
}
}
Wenn ich das Programm starte, erhalte ich Rechtecke, die zum Teil mit Farbe ausgefüllt sind und zum Teil nur farbige Rahmen haben, aber eigentlich dürften doch alle nur farbige Rahmen bekommen oder?