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:
33
examples/zm_formen/Dreieck.java
Normal file
33
examples/zm_formen/Dreieck.java
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse Dreieck.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class Dreieck
|
||||
{
|
||||
// Instanzvariablen - ersetzen Sie das folgende Beispiel mit Ihren Variablen
|
||||
private int x;
|
||||
|
||||
/**
|
||||
* Konstruktor für Objekte der Klasse Dreieck
|
||||
*/
|
||||
public Dreieck()
|
||||
{
|
||||
// Instanzvariable initialisieren
|
||||
x = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Beispiel einer Methode - ersetzen Sie diesen Kommentar mit Ihrem eigenen
|
||||
*
|
||||
* @param y ein Beispielparameter für eine Methode
|
||||
* @return die Summe aus x und y
|
||||
*/
|
||||
public int beispielMethode(int y)
|
||||
{
|
||||
// tragen Sie hier den Code ein
|
||||
return x + y;
|
||||
}
|
||||
}
|
||||
88
examples/zm_formen/Kreis.java
Normal file
88
examples/zm_formen/Kreis.java
Normal file
@@ -0,0 +1,88 @@
|
||||
import schule.ngb.zm.Color;
|
||||
import schule.ngb.zm.Drawable;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class Kreis implements Drawable {
|
||||
|
||||
private int x;
|
||||
|
||||
private int y;
|
||||
|
||||
private int radius;
|
||||
|
||||
private Color farbe;
|
||||
|
||||
private Color linienfarbe;
|
||||
|
||||
private boolean sichtbar;
|
||||
|
||||
public Kreis() {
|
||||
x = 420;
|
||||
y = 420;
|
||||
|
||||
radius = 80;
|
||||
|
||||
farbe = Color.BLUE;
|
||||
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 setRadius( int pRadius ) {
|
||||
radius = pRadius;
|
||||
}
|
||||
|
||||
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-(radius/2.0) > 0 && x+(radius/2.0) < 800 && y-(radius/2.0) > 0 && y+(radius/2.0) < 800 ) {
|
||||
graphics.setColor(farbe.getJavaColor());
|
||||
graphics.fillOval(x, y, radius, radius);
|
||||
graphics.setColor(linienfarbe.getJavaColor());
|
||||
graphics.drawOval(x, y, radius, radius);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
29
examples/zm_formen/Leinwand.java
Normal file
29
examples/zm_formen/Leinwand.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import schule.ngb.zm.Drawable;
|
||||
import schule.ngb.zm.DrawableLayer;
|
||||
import schule.ngb.zm.Zeichenmaschine;
|
||||
|
||||
public class Leinwand {
|
||||
|
||||
private final Zeichenmaschine zm;
|
||||
|
||||
private final DrawableLayer zeichenflaeche;
|
||||
|
||||
public Leinwand() {
|
||||
zm = new Zeichenmaschine(800, 800, "ZM: Shapes", false);
|
||||
zeichenflaeche = new DrawableLayer();
|
||||
zm.addLayer(zeichenflaeche);
|
||||
}
|
||||
|
||||
public void anzeigen( Drawable pForm ) {
|
||||
zeichenflaeche.add(pForm);
|
||||
}
|
||||
|
||||
public void beenden() {
|
||||
zm.exit();
|
||||
}
|
||||
|
||||
public void zeichnen() {
|
||||
zm.redraw();
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
53
examples/zm_formen/package.bluej
Normal file
53
examples/zm_formen/package.bluej
Normal file
@@ -0,0 +1,53 @@
|
||||
#BlueJ package file
|
||||
editor.fx.0.height=728
|
||||
editor.fx.0.width=800
|
||||
editor.fx.0.x=488
|
||||
editor.fx.0.y=107
|
||||
objectbench.height=94
|
||||
objectbench.width=776
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8305369127516778
|
||||
package.editor.height=488
|
||||
package.editor.width=661
|
||||
package.editor.x=36
|
||||
package.editor.y=155
|
||||
package.frame.height=660
|
||||
package.frame.width=800
|
||||
package.numDependencies=0
|
||||
package.numTargets=4
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=48
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=30
|
||||
target1.name=Rechteck
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=70
|
||||
target1.x=190
|
||||
target1.y=50
|
||||
target2.height=30
|
||||
target2.name=Dreieck
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=70
|
||||
target2.x=190
|
||||
target2.y=170
|
||||
target3.height=30
|
||||
target3.name=Kreis
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=70
|
||||
target3.x=190
|
||||
target3.y=110
|
||||
target4.height=60
|
||||
target4.name=Leinwand
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=40
|
||||
target4.y=100
|
||||
Reference in New Issue
Block a user