mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 01:45:18 +02:00
Viele weitere Beispielprojekt für verschiedene Anwendungen
This commit is contained in:
95
examples/zm_formen/Rechteck.java
Normal file
95
examples/zm_formen/Rechteck.java
Normal file
@@ -0,0 +1,95 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Drawable;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class Rechteck implements Drawable {
|
||||
|
||||
private int x;
|
||||
|
||||
private int y;
|
||||
|
||||
private int breite;
|
||||
|
||||
private int hoehe;
|
||||
|
||||
private Color farbe;
|
||||
|
||||
private Color linienfarbe;
|
||||
|
||||
private boolean sichtbar;
|
||||
|
||||
public Rechteck() {
|
||||
x = 320;
|
||||
y = 240;
|
||||
|
||||
breite = 100;
|
||||
hoehe = 60;
|
||||
|
||||
farbe = Color.RED;
|
||||
linienfarbe = Color.BLACK;
|
||||
|
||||
sichtbar = true;
|
||||
}
|
||||
|
||||
public void anzeigen() {
|
||||
sichtbar = true;
|
||||
}
|
||||
|
||||
public void verstecken() {
|
||||
sichtbar = false;
|
||||
}
|
||||
|
||||
public void setPosition( int pX, int pY ) {
|
||||
x = pX;
|
||||
y = pY;
|
||||
}
|
||||
|
||||
public void links() {
|
||||
x -= 10;
|
||||
}
|
||||
|
||||
public void rechts() {
|
||||
x += 10;
|
||||
}
|
||||
|
||||
public void hoch() {
|
||||
y -= 10;
|
||||
}
|
||||
|
||||
public void runter() {
|
||||
y += 10;
|
||||
}
|
||||
|
||||
public void setBreite( int pBreite ) {
|
||||
breite = pBreite;
|
||||
}
|
||||
|
||||
public void setHoehe( int pHoehe ) {
|
||||
hoehe = pHoehe;
|
||||
}
|
||||
|
||||
public void setFarbe( String pFarbe ) {
|
||||
farbe = Color.parseString(pFarbe);
|
||||
}
|
||||
|
||||
public void setLinienfarbe( String pLinienfarbe ) {
|
||||
linienfarbe = Color.parseString(pLinienfarbe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return sichtbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw( Graphics2D graphics ) {
|
||||
if( x-(breite/2.0) > 0 && x+(breite/2.0) < 800 && y-(hoehe/2.0) > 0 && y+(hoehe/2.0) < 800 ) {
|
||||
graphics.setColor(farbe.getJavaColor());
|
||||
graphics.fillRect(x, y, breite, hoehe);
|
||||
graphics.setColor(linienfarbe.getJavaColor());
|
||||
graphics.drawRect(x, y, breite, hoehe);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user