Jan 4 years ago
parent
commit
132b8c35d5

+ 88
- 50
Garten/src/garten/model/Gaertner.java View File

@@ -14,7 +14,9 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import javax.security.auth.callback.ConfirmationCallback;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

/**
*
@@ -25,12 +27,12 @@ public class Gaertner implements MouseMotionListener, MouseListener,
{
private Garten meinGarten;
private Fenster fenster;
private FlaecheBeet flbeet;
private FlaecheWeg flweg;
private FlaechePflanzen flpfl;
private boolean pflanzebewegt;
private ArrayList<Pflanze> pflanzen;
private ArrayList<Beet> beete;
private boolean gartenexistiert;
private boolean bepflanzungexistiert;
private Beet bepflanzeBeet;

MouseEvent koordinbeet; //x,y Koordinaten reichen eigentlich

Pflanze1 pfl1;
Pflanze2 pfl2;
@@ -38,54 +40,14 @@ public class Gaertner implements MouseMotionListener, MouseListener,
int height;
int width;

int[] randomwertex;
int[] randomwertey;

public Gaertner(Fenster fenster, FlaecheBeet flbeet, FlaecheWeg flweg,
FlaechePflanzen flpfl)
{
meinGarten = new Garten(flbeet, flweg, flpfl);
this.fenster = fenster; //Zur späteren Steuerung Pop up usw.
this.flpfl = flpfl;

pflanzen = new ArrayList<>();
beete = new ArrayList<>();

pflanzebewegt = false;
//Initialisierung der Wege/Beete
height = fenster.getHeight();
width = fenster.getWidth();
randomwertex = new int[4];
randomwertey = new int[4];
randomwertex[0] = 10;
randomwertey[0] = 10;
randomwertex[3] = width - 50;
randomwertey[3] = height - 50;

for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete
{
int wegendex = (int) (Math.random() * (170 * i) + (200 * i));
int wegendey = (int) (Math.random() * (170 * i) + (200 * i));
randomwertex[i] = wegendex;
randomwertey[i] = wegendey;
}

for (int i = 0; i < randomwertex.length; i++) //Garten Wege hinzufügen
{
meinGarten.hinzufuegenWeg(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]);
meinGarten.hinzufuegenWeg(randomwertex[0], randomwertey[i], randomwertex[3], randomwertey[i]);
}
for (int i = 0; i < randomwertex.length - 1; i++) //Garten Beete hinzufügen
{
for (int j = 0; j < randomwertey.length - 1; j++)
{
meinGarten.hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1] - randomwertex[i] - 20, randomwertey[j + 1] - randomwertey[j] - 20);
}
}
meinGarten.zeichneWeg();
meinGarten.zeichneBeete();
meinGarten.randomBepflanzung();
meinGarten.zeichnePflanzen();
gartenexistiert = false;
bepflanzungexistiert = false;

}

@@ -93,17 +55,38 @@ public class Gaertner implements MouseMotionListener, MouseListener,
{
fenster.addMouseListener(this);
fenster.addMouseMotionListener(this);

fenster.getMnGartenanlegen().addActionListener(this);
fenster.getMnRandomPflanzenanlegen().addActionListener(this);

fenster.getMnbepflanzen1().addActionListener(this);
fenster.getMnbepflanzen2().addActionListener(this);
fenster.getMnbepflanzen3().addActionListener(this);

fenster.getBtnbepfl1().addActionListener(this);
fenster.getBtnbepfl2().addActionListener(this);
fenster.getBtnbepfl3().addActionListener(this);

}

@Override
public void mouseClicked(MouseEvent e)
{

if (SwingUtilities.isRightMouseButton(e))//Bei Rechtsklick Popup Menü
{
koordinbeet =e; //abspeichern wegen koordinaten zur weiterverarbeitung
fenster.showPoPup(e);
}
else
{
fenster.hidePopup();
}
}

@Override
public void mousePressed(MouseEvent e)
{

}

@Override
@@ -125,27 +108,82 @@ public class Gaertner implements MouseMotionListener, MouseListener,
@Override
public void mouseExited(MouseEvent e)
{

}

@Override
public void actionPerformed(ActionEvent e)
{
Object key = e.getSource();
if (key.equals(fenster.getMnGartenanlegen())) //Garten anlegen
{
if (gartenexistiert == false)
{
meinGarten.erstelleGarten();
gartenexistiert = true;
}
else //Falls schon angelegt nachfragen ob neu anlegen
{
if (JOptionPane.showConfirmDialog(fenster, "Garten neu anlegen?", "Info", JOptionPane.YES_NO_OPTION) == ConfirmationCallback.YES)
{
meinGarten.löscheGarten();
meinGarten.erstelleGarten();
gartenexistiert = true;
bepflanzungexistiert = false;
}
}
}
else if (key.equals(fenster.getMnRandomPflanzenanlegen())) //Garten Random Bepflanzen
{
if (gartenexistiert == true && bepflanzungexistiert == false) //falls garten existiert bepflanzen
{
if (meinGarten.randomBepflanzung() == true)
{
bepflanzungexistiert = true;
}
else
{
JOptionPane.showConfirmDialog(null,
"Beet war leider für eine Pflanzengruppe zu klein", "Info", JOptionPane.DEFAULT_OPTION);
}
}
else if (gartenexistiert == true && bepflanzungexistiert == true)//falls schon ein teil bepflanzt
{
if (JOptionPane.showConfirmDialog(fenster, "Beete neu bepflanzen?", "Info?", JOptionPane.YES_NO_OPTION) == ConfirmationCallback.YES)
{
meinGarten.löscheBepflanzung();
meinGarten.randomBepflanzung();
bepflanzungexistiert = true;
}
}
else
{
JOptionPane.showConfirmDialog(fenster, "Erst muss ein Garten angelegt werden", "Info", JOptionPane.DEFAULT_OPTION);
}
}
else if (key.equals(fenster.getBtnbepfl1()) || key.equals(fenster.getBtnbepfl2()) ||key.equals(fenster.getBtnbepfl3()))
{
}
}

@Override
public void mouseDragged(MouseEvent e)
{
fenster.hidePopup();
if (pflanzebewegt == false)
{
{
if (meinGarten.getmovePflanze(e) != null)
{
pflanzebewegt = true;
}
}

}

@Override
public void mouseMoved(MouseEvent e)
{
}

}

+ 142
- 82
Garten/src/garten/model/Garten.java View File

@@ -20,7 +20,8 @@ public class Garten extends Kompositum
private ArrayList<Weg> wege;
private ArrayList<Beet> beete;
private ArrayList<Pflanze> pflanzen;

private Pflanze pfl;
private Pflanze1 pfl1;
private Pflanze2 pfl2;
private Pflanze3 pfl3;
@@ -29,128 +30,211 @@ public class Garten extends Kompositum
FlaecheWeg flweg;
FlaechePflanzen flpfl;

public Garten(FlaecheBeet flbeet,FlaecheWeg flweg,FlaechePflanzen flpfl)
public Garten(FlaecheBeet flbeet, FlaecheWeg flweg, FlaechePflanzen flpfl)
{
wege = new ArrayList();
beete = new ArrayList();
pflanzen = new ArrayList();
this.flbeet = flbeet;
this.flweg = flweg;
this.flpfl = flpfl;
}

//Funktionen Beete
public void hinzufuegenBeet(int x, int y, int a, int b)
{
Beet neuesBeet = new Beet(x, y, a, b);
beete.add(neuesBeet);
}

public ArrayList<Beet> getBeete()
{
return beete;
}

public void zeichneBeete()
{
flbeet.zeichneBeete(beete);
}
//Funktionen Wege
/*
public int getBeet(MouseEvent e)
{
Beet tempBeet;
for (Beet b : beete)
{
tempBeet = b;
}

//return tempBeet;
}
//Funktionen Wege
*/
public void hinzufuegenWeg(int sx, int sy, int ex, int ey)
{
Weg neuerWeg = new Weg(sx, sy, ex, ey);
wege.add(neuerWeg);
}

public void zeichneWeg()
{
flweg.zeichneWeg(wege);
}

//Funktionen Pflanzen
public void hinzufuegenPflanze(Pflanze pflanze)
{
pflanzen.add(pflanze);
}

public void zeichnePflanzen()
{
flpfl.setPflanzen(pflanzen);
}
public void randomBepflanzung()

public Boolean randomBepflanzung()
{
for (Beet b : beete)
{
int randomAlter = (int) (Math.random() * 3 + 1);
int randomTyp = (int) (Math.random() * 3 + 1);
Boolean bepflanzung = true;
Boolean versetzt = true;
int[] temp = b.getKoordinaten();

int tempx = temp[0]+10;
int tempy = temp[1]+20;
int tempxrand = temp[2] + temp[0];
int tempyrand = temp[3] + temp[1];
int deltax = (temp[2]-40)/((temp[2]-40)/40);
int deltay = (temp[3]-40)/((temp[3]-40)/50);
do
try
{
if (randomTyp == 1)
{
pfl1 = new Pflanze1(tempx, tempy, randomAlter);
hinzufuegenPflanze(pfl1);
}
else if (randomTyp == 2)
{
pfl2 = new Pflanze2(tempx, tempy, randomAlter);
hinzufuegenPflanze(pfl2);
}
else if (randomTyp == 3)
{
pfl3 = new Pflanze3(tempx, tempy, randomAlter);
hinzufuegenPflanze(pfl3);
}
tempx += deltax;
if (tempx > tempxrand )

int randomAlter = (int) (Math.random() * 3 + 1);
int randomTyp = (int) (Math.random() * 3 + 1);
Boolean bepflanzung = true;
Boolean versetzt = true;
int[] temp = b.getKoordinaten();

int tempx = temp[0] + 10;
int tempy = temp[1] + 20;
int tempxrand = temp[2] + temp[0];
int tempyrand = temp[3] + temp[1];

int deltax = (temp[2] - 40) / ((temp[2] - 40) / 40);
int deltay = (temp[3] - 40) / ((temp[3] - 40) / 50);
do
{
if (versetzt)
if (randomTyp == 1)
{
tempx = temp[0]+30;
versetzt = false;
pfl1 = new Pflanze1(tempx, tempy, randomAlter,20);
float[] tempbound = pfl1.getBoundingBoxes();
System.out.println("Bounding Boxes: " + tempbound[0] + " " + tempbound[1] + " " + tempbound[2] + " " + tempbound[3]);
hinzufuegenPflanze(pfl1);
}
else
else if (randomTyp == 2)
{
tempx = temp[0]+20;
versetzt = true;
pfl2 = new Pflanze2(tempx, tempy, randomAlter,15);
hinzufuegenPflanze(pfl2);
}
else if (randomTyp == 3)
{
pfl3 = new Pflanze3(tempx, tempy, randomAlter,10);
hinzufuegenPflanze(pfl3);
}
tempx += deltax;
if (tempx > tempxrand)
{
if (versetzt)
{
tempx = temp[0] + 30;
versetzt = false;
}
else
{
tempx = temp[0] + 20;
versetzt = true;
}
tempy += deltay;
}
if (tempy > tempyrand)
{
bepflanzung = false;
}
tempy += deltay;
}
if (tempy > tempyrand)
{
bepflanzung = false;
}
while (bepflanzung);
}
catch (ArithmeticException e)
{
pflanzen.removeAll(pflanzen);
return false;
}
while (bepflanzung);
}
zeichnePflanzen();
return true;
}

public void löscheBepflanzung()
{
pflanzen.removeAll(pflanzen);
flpfl.löschePflanzen();
}

public void erstelleGarten()
{
int height = flbeet.getHeight();
int width = flbeet.getWidth();
int[] randomwertex = new int[4];
int[] randomwertey = new int[4];
randomwertex[0] = 10;
randomwertey[0] = 10;
randomwertex[3] = width - 50;
randomwertey[3] = height - 50;

for (int i = 1; i < 3; i++) //erstelle Random Punkte für Wege + Beete
{
int wegendex = (int) (Math.random() * (170 * i) + (200 * i));
int wegendey = (int) (Math.random() * (170 * i) + (200 * i));
randomwertex[i] = wegendex;
randomwertey[i] = wegendey;
}

for (int i = 0; i < randomwertex.length; i++) //Garten Wege hinzufügen
{
hinzufuegenWeg(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]);
hinzufuegenWeg(randomwertex[0], randomwertey[i], randomwertex[3], randomwertey[i]);
}
for (int i = 0; i < randomwertex.length - 1; i++) //Garten Beete hinzufügen
{
for (int j = 0; j < randomwertey.length - 1; j++)
{
hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1] - randomwertex[i] - 20, randomwertey[j + 1] - randomwertey[j] - 20);
}
}
zeichneWeg();
zeichneBeete();
}

public void löscheGarten()
{
wege.removeAll(wege);
beete.removeAll(beete);
pflanzen.removeAll(pflanzen);
flpfl.löschePflanzen();
flbeet.löscheBeete();
flweg.löscheWeg();
}

public Pflanze getmovePflanze(MouseEvent e)
{
Pflanze diePflanze = null;
int abstand = 30;

for(int i = 0; i< pflanzen.size();i++)
for (int i = 0; i < pflanzen.size(); i++)
{
if( Math.abs(pflanzen.get(i).getPositionx()-e.getX()) + Math.abs(pflanzen.get(i).getPositiony()-e.getY()) < abstand)
if (Math.abs(pflanzen.get(i).getPositionx() - e.getX()) + Math.abs(pflanzen.get(i).getPositiony() - e.getY()) < abstand)
{
diePflanze = pflanzen.get(i);
abstand = Math.abs(pflanzen.get(i).getPositionx()-e.getX()) + Math.abs(pflanzen.get(i).getPositiony()-e.getY());
System.out.println("Pflanze: " +diePflanze.getPositionx() + " " + diePflanze.getPositiony());
abstand = Math.abs(pflanzen.get(i).getPositionx() - e.getX()) + Math.abs(pflanzen.get(i).getPositiony() - e.getY());
System.out.println("Pflanze: " + diePflanze.getPositionx() + " " + diePflanze.getPositiony());

intmovePflanze = i;
System.out.println("Alte Position: "+pflanzen.get(intmovePflanze).getPositionx() + " " +pflanzen.get(intmovePflanze).getPositiony());
System.out.println("Alte Position: " + pflanzen.get(intmovePflanze).getPositionx() + " " + pflanzen.get(intmovePflanze).getPositiony());
}
}
return diePflanze;
}

public void setmovePflanze(MouseEvent e)
{
pflanzen.get(intmovePflanze).setPositionx(e.getX());
@@ -158,29 +242,5 @@ public class Garten extends Kompositum
pflanzen.get(intmovePflanze).setAlgorithm();
zeichnePflanzen();
}
/*
public Pflanze naechstePflanze(int x, int y)
{
Pflanze diePflanze = null;
int abstand = 1000;
for(int i = 0; i < pflanzen.size(); i++)
{
if(pflanzen.get(i).getPositionx()-x + pflanzen.get(i).getPositiony()-y < abstand)
{
diePflanze = pflanzen.get(i);
abstand = Math.abs(x-pflanzen.get(i).getPositionx()) + Math.abs(y-pflanzen.get(i).getPositiony()) ;
print(pflanzen.get(i).getPositionx());
print(pflanzen.get(i).getPositiony());
}
}
if(abstand < 20)
{
return diePflanze;
}
else
{
return null;
}
}
*/

}

+ 3
- 4
Garten/src/garten/model/Pflanze1.java View File

@@ -14,11 +14,10 @@ import lsystem.StochasticGrammar;

class Pflanze1 extends PflanzeImpl
{
Pflanze1(int Xstart, int Ystart, int Generation)
Pflanze1(int Xstart, int Ystart, int Generation,int startLength)//30-50, Generations 3
{
super(Xstart,Ystart,Generation);
super(Xstart,Ystart,Generation,startLength);
DELTA = (float) ((Math.PI)/10);
startLength = 30;
createLSystem();
translateRules();
}
@@ -29,6 +28,6 @@ class Pflanze1 extends PflanzeImpl
grammar.addRule('F',"F[+F]F", (float) 0.45);
grammar.addRule('F',"F[-F]F", (float) 0.45);
grammar.generateGrammar(generations);
drawLength =(float) (startLength * Math.pow(0.7, (double) generations));
drawLength =(float) (startLength * Math.pow(0.6, (double) generations));
}
}

+ 2
- 4
Garten/src/garten/model/Pflanze2.java View File

@@ -14,12 +14,10 @@ import lsystem.StochasticGrammar;

class Pflanze2 extends PflanzeImpl
{
Pflanze2(int Xstart, int Ystart, int Generation)
Pflanze2(int Xstart, int Ystart, int Generation,int startLength)//startLength 10-20 (Verzweigte Pflanze)3 Generationen
{
super(Xstart,Ystart,Generation);
super(Xstart,Ystart,Generation,startLength);
DELTA = (float) ((Math.PI)/5);
startLength = 10;
createLSystem();
translateRules();
}

+ 2
- 4
Garten/src/garten/model/Pflanze3.java View File

@@ -14,12 +14,10 @@ import lsystem.StochasticGrammar;

class Pflanze3 extends PflanzeImpl
{
Pflanze3(int Xstart, int Ystart, int Generation)
Pflanze3(int Xstart, int Ystart, int Generation,int startLength) //Unkraut 10-20, 4 Generations
{
super(Xstart,Ystart,Generation);
super(Xstart,Ystart,Generation,startLength);
DELTA = (float) ((Math.PI)/5);
startLength = 10;
createLSystem();
translateRules();
}

+ 32
- 4
Garten/src/garten/model/PflanzeImpl.java View File

@@ -11,6 +11,7 @@ package garten.model;
*/
import java.text.CharacterIterator;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JComponent;
import lsystem.Grammar;
import lsystem.collection.TurtleStack;
@@ -34,16 +35,24 @@ public class PflanzeImpl extends JComponent implements Pflanze
protected int positiony;

protected int flaeche;

protected float[] boundingBoxes;
ArrayList<Float> tempx;
ArrayList<Float> tempy;
//Position();
TurtleStack ts;

public PflanzeImpl(int Xstart, int Ystart, int Generation)
public PflanzeImpl(int xstart, int ystart, int generation, int startLength)
{
positionx = Xstart;
positiony = Ystart;
generations = Generation;
this.positionx = xstart;
this.positiony = ystart;
this.generations = generation;
this.startLength = startLength;
pts = new ArrayList<float[]>();
ts = new TurtleStack();
boundingBoxes=new float[4]; //minx, miny, maxx, maxy
tempx = new ArrayList<>();
tempy = new ArrayList<>();
}

public void translateRules()
@@ -65,7 +74,13 @@ public class PflanzeImpl extends JComponent implements Pflanze
{
x_temp, y_temp, turtle.getX(), turtle.getY()
};
tempx.add(x_temp);
tempx.add(turtle.getX());
tempy.add(y_temp);
tempy.add(turtle.getY());

pts.add(temp);

break;
case '+':
turtle.setTheta(turtle.getTheta() + DELTA);
@@ -83,12 +98,25 @@ public class PflanzeImpl extends JComponent implements Pflanze
System.err.println("character " + ch + " not in grammar");
}
}
setBoundingBoxes();
}

void setBoundingBoxes()
{
boundingBoxes[0] = Collections.min(tempx);
boundingBoxes[1] = Collections.min(tempy);
boundingBoxes[2] = Collections.max(tempx);
boundingBoxes[3] = Collections.max(tempy);
}
public float [] getBoundingBoxes()
{
return boundingBoxes;
}

@Override
public ArrayList<float[]> getPoints()
{

return pts;
}


+ 8
- 9
Garten/src/garten/model/Pflanzengruppe.java View File

@@ -14,19 +14,18 @@ class Pflanzengruppe
{
private int alter;
private int pflanzentyp;
private int startlaenge;
Pflanze1 pfl1;
Pflanze2 pfl2;
Pflanze3 pfl3;
private int anzahlPflanzen = 1;
//Pflanze[] Pflanzengruppe = new Pflanze[anzahlPflanzen];
Pflanzengruppe(int Alter,int PflanzenTyp,int AnzahlPflanzen)
Pflanzengruppe(int pflanzenTyp,int alter, int startlaenge)
{
alter = Alter;
pflanzentyp = PflanzenTyp;
anzahlPflanzen = AnzahlPflanzen;
this.alter = alter;
this.pflanzentyp = pflanzenTyp;
this.startlaenge = startlaenge;
}
public void anzeigen()
{

+ 21
- 22
Garten/src/garten/model/PflanzengruppenKonfigurator.java View File

@@ -13,53 +13,52 @@ package garten.model;
class PflanzengruppenKonfigurator
{
private int alter = 1;
private int pflanzenTyp = 1;
private int anzahlPflanzen = 1;
private int pflanzenTyp =1;
private int startlaenge =1;
public PflanzengruppenKonfigurator()
{

}
public PflanzengruppenKonfigurator alter(int Alter)
public Pflanzengruppe erstellen() throws IllegalArgumentException
{
this.alter = Alter;
return this;
konfigurationPruefen();
Pflanzengruppe pflgruppe = new Pflanzengruppe(pflanzenTyp,alter,startlaenge);
return pflgruppe;
}
public PflanzengruppenKonfigurator pflanzenTyp(int PflanzenTyp)
public PflanzengruppenKonfigurator alter(int alter)
{
this.pflanzenTyp = PflanzenTyp;
this.alter = alter;
return this;
}
public PflanzengruppenKonfigurator anzahlPflanzen(int AnzahlPflanzen)
public PflanzengruppenKonfigurator pflanzenTyp(int pflanzenTyp)
{
this.anzahlPflanzen = AnzahlPflanzen;
this.pflanzenTyp = pflanzenTyp;
return this;
}

public void setanzPflanzen(int tempanz)
public PflanzengruppenKonfigurator startlaenge(int startlaenge)
{
anzahlPflanzen=tempanz;
this.startlaenge = startlaenge;
return this;
}
public Pflanzengruppe erstellen() throws IllegalArgumentException
{
konfigurationPruefen();
Pflanzengruppe pflgruppe = new Pflanzengruppe(alter,pflanzenTyp,anzahlPflanzen);
return pflgruppe;
}
private void konfigurationPruefen() throws IllegalArgumentException
{
if((this.pflanzenTyp ==2 ||this.pflanzenTyp ==3 )&& alter > 4)
if((pflanzenTyp ==1 || pflanzenTyp ==2) && alter > 3|| pflanzenTyp ==3 && alter > 4)
{
throw new IllegalArgumentException("Ein geringeres Alter muss gewählt werden");
}
if(this.pflanzenTyp ==1 && alter > 5)
if(pflanzenTyp ==1 && (startlaenge < 30 || startlaenge >50))
{
throw new IllegalArgumentException("Ein geringeres Alter muss gewählt werden");
throw new IllegalArgumentException("Größe muss zwischen 30-50 liegen");
}
if((pflanzenTyp ==2 || pflanzenTyp ==3) && (startlaenge <10 || startlaenge >20))
{
throw new IllegalArgumentException("Größe muss zwischen 10-20 liegen");
}
}

+ 7
- 6
Garten/src/garten/start.java View File

@@ -23,24 +23,25 @@ public class start
{
public start()
{
Color hintergrund = new Color(34, 139, 34);
Fenster view = new Fenster();
FlaecheBeet flbeet = new FlaecheBeet();
FlaecheWeg flweg = new FlaecheWeg();
FlaechePflanzen flpflanzen = new FlaechePflanzen();
Fenster view = new Fenster();
flpflanzen.setOpaque(false);
flweg.setOpaque(false);
flbeet.setOpaque(false);
flbeet.setComponentPopupMenu(view.getPopup());
flweg.setOpaque(false);
Container hauptkiste = view.getContentPane();
hauptkiste.setLayout(new OverlayLayout(hauptkiste));
hauptkiste.setBackground(hintergrund);
hauptkiste.add(flpflanzen);
hauptkiste.add(flbeet);
hauptkiste.add(flweg);
Gaertner ga = new Gaertner(view,flbeet,flweg,flpflanzen);
ga.registerEvents();
}

+ 160
- 12
Garten/src/garten/view/Fenster.java View File

@@ -5,7 +5,15 @@
*/
package garten.view;

import java.awt.MouseInfo;
import java.awt.event.MouseEvent;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;

/**
*
@@ -13,22 +21,114 @@ import javax.swing.JFrame;
*/
public class Fenster extends JFrame
{

JPopupMenu popup;
JMenu mnbepflanzen1;
JMenu mnbepflanzen2;
JMenu mnbepflanzen3;
JMenuItem mnGartenanlegen;
JMenuItem mnRandomPflanzenanlegen;
JButton btnbepfl1;
JButton btnbepfl2;
JButton btnbepfl3;
JRadioButton radiobtn1pfl1;
JRadioButton radiobtn2pfl1;
JRadioButton radiobtn3pfl1;
JRadioButton radiobtn4pfl1;
JRadioButton radiobtn1pfl2;
JRadioButton radiobtn2pfl2;
JRadioButton radiobtn3pfl2;
JRadioButton radiobtn4pfl2;
JRadioButton radiobtn1pfl3;
JRadioButton radiobtn2pfl3;
JRadioButton radiobtn3pfl3;
JRadioButton radiobtn4pfl3;
public Fenster()
{
//PoPupMenü
popup = new JPopupMenu();
mnGartenanlegen = new JMenuItem("Garten anlegen");
mnRandomPflanzenanlegen = new JMenuItem("Random Bepflanzung");
popup.add(mnGartenanlegen);
popup.addSeparator();
popup.add(mnRandomPflanzenanlegen);
popup.addSeparator();
//PopUpmenü Pflanze 1
mnbepflanzen1 = new JMenu("Bepflanze mit Pflanze1");
btnbepfl1 = new JButton("Bepflanzen");
radiobtn1pfl1 = new JRadioButton("1 Jahr alt");
radiobtn2pfl1 = new JRadioButton("2 Jahre alt");
radiobtn3pfl1= new JRadioButton("3 Jahre alt");
radiobtn4pfl1 = new JRadioButton("4 Jahre alt");
//Btn Gruppe Pflanz1
ButtonGroup radiobtngrp1 = new ButtonGroup();
radiobtngrp1.add(radiobtn1pfl1);
radiobtngrp1.add(radiobtn2pfl1);
radiobtngrp1.add(radiobtn3pfl1);
radiobtngrp1.add(radiobtn4pfl1);
//Alle Elemente zu PopUpmenü Pflanze 1 hinzufügen
mnbepflanzen1.add(radiobtn1pfl1);
mnbepflanzen1.add(radiobtn2pfl1);
mnbepflanzen1.add(radiobtn3pfl1);
mnbepflanzen1.add(radiobtn4pfl1);
mnbepflanzen1.add(btnbepfl1);
//PopUpmenü Pflanze 2
mnbepflanzen2 = new JMenu("Bepflanze mit Pflanze2");
btnbepfl2 = new JButton("Bepflanzen");
radiobtn1pfl2 = new JRadioButton("1 Jahr alt");
radiobtn2pfl2 = new JRadioButton("2 Jahre alt");
radiobtn3pfl2= new JRadioButton("3 Jahre alt");
radiobtn4pfl2= new JRadioButton("4 Jahre alt");
//Btn Gruppe Pflanz2
radiobtngrp1.add(radiobtn1pfl2);
radiobtngrp1.add(radiobtn2pfl2);
radiobtngrp1.add(radiobtn3pfl2);
radiobtngrp1.add(radiobtn4pfl2);
//Alle Elemente zu PopUpmenü Pflanze 2 hinzufügen
mnbepflanzen2.add(radiobtn1pfl2);
mnbepflanzen2.add(radiobtn2pfl2);
mnbepflanzen2.add(radiobtn3pfl2);
mnbepflanzen2.add(radiobtn4pfl2);
mnbepflanzen2.add(btnbepfl2);

/*
JPopupMenu popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Hallo");
JRadioButtonMenuItem radioButtonItem = new JRadioButtonMenuItem("Ich bin ein JRadionButtonMenuItem",true);
popup.add(menuItem);
popup.add(radioButtonItem);
popup.setLocation(200,200);
popup.setVisible(true);
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
popup.setVisible(true);
//PopUpmenü Pflanze 3
mnbepflanzen3 = new JMenu("Bepflanze mit Pflanze3");
btnbepfl3 = new JButton("Bepflanzen");
*/
radiobtn1pfl3 = new JRadioButton("1 Jahr alt");
radiobtn2pfl3 = new JRadioButton("2 Jahre alt");
radiobtn3pfl3= new JRadioButton("3 Jahre alt");
radiobtn4pfl3= new JRadioButton("4 Jahre alt");
//Btn Gruppe Pflanz3
radiobtngrp1.add(radiobtn1pfl3);
radiobtngrp1.add(radiobtn2pfl3);
radiobtngrp1.add(radiobtn3pfl3);
radiobtngrp1.add(radiobtn4pfl3);
//Alle Elemente zu PopUpmenü Pflanze 3 hinzufügen
mnbepflanzen3.add(radiobtn1pfl3);
mnbepflanzen3.add(radiobtn2pfl3);
mnbepflanzen3.add(radiobtn3pfl3);
mnbepflanzen3.add(radiobtn4pfl3);
mnbepflanzen3.add(btnbepfl3);
//Alle PopUpmenüs dem PoPup hinzufügen
popup.add(mnbepflanzen1);
popup.addSeparator();
popup.add(mnbepflanzen2);
popup.addSeparator();
popup.add(mnbepflanzen3);
this.setTitle("Garten von Paul und Jan");
this.pack();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
@@ -36,4 +136,52 @@ public class Fenster extends JFrame
this.setVisible(true);
}
public void showPoPup(MouseEvent e)
{
popup.setLocation(MouseInfo.getPointerInfo().getLocation().x,MouseInfo.getPointerInfo().getLocation().y);
popup.setVisible(true);
}
public void hidePopup()
{
popup.setVisible(false);
}
public JPopupMenu getPopup()
{
return popup;
}
public JMenuItem getMnGartenanlegen()
{
return mnGartenanlegen;
}
public JMenuItem getMnRandomPflanzenanlegen()
{
return mnRandomPflanzenanlegen;
}
public JMenu getMnbepflanzen1()
{
return mnbepflanzen1;
}
public JMenu getMnbepflanzen2()
{
return mnbepflanzen2;
}
public JMenu getMnbepflanzen3()
{
return mnbepflanzen3;
}
public JButton getBtnbepfl1()
{
return btnbepfl1;
}
public JButton getBtnbepfl2()
{
return btnbepfl2;
}
public JButton getBtnbepfl3()
{
return btnbepfl2;
}
}

+ 6
- 1
Garten/src/garten/view/FlaecheBeet.java View File

@@ -18,7 +18,6 @@ import javax.swing.JPanel;
public class FlaecheBeet extends JPanel
{
int[] temppunkte;

Color colorBeet;
private ArrayList<Beet> beete;

@@ -44,7 +43,13 @@ public class FlaecheBeet extends JPanel

public void zeichneBeete(ArrayList<Beet> tempBeet)
{
beete.addAll(0, tempBeet);
repaint();
}
public void löscheBeete()
{
beete.removeAll(beete);
repaint();
}
}

+ 6
- 0
Garten/src/garten/view/FlaechePflanzen.java View File

@@ -31,6 +31,7 @@ public class FlaechePflanzen extends JPanel
pflanzen = new ArrayList<>();
Gerade = new Line2D.Float();
pinsel = new BasicStroke(1f);
}

public void paintComponent(Graphics g)
@@ -57,4 +58,9 @@ public class FlaechePflanzen extends JPanel
pflanzen.addAll(0, temppflanzen);
repaint();
}
public void löschePflanzen()
{
pflanzen.removeAll(pflanzen);
repaint();
}
}

+ 4
- 0
Garten/src/garten/view/FlaecheWeg.java View File

@@ -53,4 +53,8 @@ public class FlaecheWeg extends JPanel
weg.addAll(0, tempWeg);
repaint();
}
public void löscheWeg()
{
weg.removeAll(weg);
}
}

+ 145
- 0
Garten/src/garten/view/GUI.form View File

@@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8" ?>

<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JPopupMenu" name="mnPopup">
<Properties>
<Property name="focusable" type="boolean" value="false"/>
</Properties>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents>
<Menu class="javax.swing.JMenu" name="mnPflanze1">
<Properties>
<Property name="text" type="java.lang.String" value="jMenu2"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JRadioButtonMenuItem" name="radiobuttonpfl1">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="jRadioButtonMenuItem1"/>
</Properties>
</MenuItem>
<MenuItem class="javax.swing.JRadioButtonMenuItem" name="jRadioButtonMenuItem1">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="jRadioButtonMenuItem1"/>
</Properties>
</MenuItem>
<MenuItem class="javax.swing.JRadioButtonMenuItem" name="jRadioButtonMenuItem2">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="jRadioButtonMenuItem2"/>
</Properties>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="mnPflanze2">
<Properties>
<Property name="text" type="java.lang.String" value="jMenu2"/>
</Properties>
</Menu>
<Menu class="javax.swing.JMenu" name="mnPflanze3">
<Properties>
<Property name="text" type="java.lang.String" value="jMenu2"/>
</Properties>
</Menu>
</SubComponents>
</Container>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents>
<Menu class="javax.swing.JMenu" name="jMenu1">
<Properties>
<Property name="text" type="java.lang.String" value="File"/>
</Properties>
</Menu>
<Menu class="javax.swing.JMenu" name="mnfunktionen">
<Properties>
<Property name="text" type="java.lang.String" value="Funktionen"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="mnzeichneGarten">
<Properties>
<Property name="text" type="java.lang.String" value="Garten anlegen"/>
</Properties>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="mnzeichneRandPflanzen">
<Properties>
<Property name="text" type="java.lang.String" value="Random Bepflanzung"/>
</Properties>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="99" green="ff" red="99" type="rgb"/>
</Property>
<Property name="componentPopupMenu" type="javax.swing.JPopupMenu" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="mnPopup"/>
</Property>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
</Constraint>
</Constraints>
<LayoutCode>
<CodeStatement>
<CodeExpression id="1_jPanel1">
<CodeVariable name="jPanel1" type="8194" declaredType="javax.swing.JPanel"/>
<ExpressionOrigin>
<ExpressionProvider type="ComponentRef">
<ComponentRef name="jPanel1"/>
</ExpressionProvider>
</ExpressionOrigin>
</CodeExpression>
<StatementProvider type="CodeMethod">
<CodeMethod name="setLayout" class="java.awt.Container" parameterTypes="java.awt.LayoutManager"/>
</StatementProvider>
<Parameters>
<CodeExpression id="2">
<ExpressionOrigin>
<ExpressionProvider type="CodeConstructor">
<CodeConstructor class="javax.swing.OverlayLayout" parameterTypes="java.awt.Container"/>
</ExpressionProvider>
<Parameters>
<CodeExpression id="1_jPanel1"/>
</Parameters>
</ExpressionOrigin>
</CodeExpression>
</Parameters>
</CodeStatement>
</LayoutCode>
</Container>
</SubComponents>
</Form>

+ 161
- 0
Garten/src/garten/view/GUI.java View File

@@ -0,0 +1,161 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package garten.view;

/**
*
* @author Jan
*/
public class GUI extends javax.swing.JFrame
{

/**
* Creates new form GUI
*/
public GUI()
{
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents()
{

mnPopup = new javax.swing.JPopupMenu();
mnPflanze1 = new javax.swing.JMenu();
radiobuttonpfl1 = new javax.swing.JRadioButtonMenuItem();
jRadioButtonMenuItem1 = new javax.swing.JRadioButtonMenuItem();
jRadioButtonMenuItem2 = new javax.swing.JRadioButtonMenuItem();
mnPflanze2 = new javax.swing.JMenu();
mnPflanze3 = new javax.swing.JMenu();
jPanel1 = new javax.swing.JPanel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
mnfunktionen = new javax.swing.JMenu();
mnzeichneGarten = new javax.swing.JMenuItem();
mnzeichneRandPflanzen = new javax.swing.JMenuItem();

mnPopup.setFocusable(false);

mnPflanze1.setText("jMenu2");

radiobuttonpfl1.setSelected(true);
radiobuttonpfl1.setText("jRadioButtonMenuItem1");
mnPflanze1.add(radiobuttonpfl1);

jRadioButtonMenuItem1.setSelected(true);
jRadioButtonMenuItem1.setText("jRadioButtonMenuItem1");
mnPflanze1.add(jRadioButtonMenuItem1);

jRadioButtonMenuItem2.setSelected(true);
jRadioButtonMenuItem2.setText("jRadioButtonMenuItem2");
mnPflanze1.add(jRadioButtonMenuItem2);

mnPopup.add(mnPflanze1);

mnPflanze2.setText("jMenu2");
mnPopup.add(mnPflanze2);

mnPflanze3.setText("jMenu2");
mnPopup.add(mnPflanze3);

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(153, 255, 153));
jPanel1.setComponentPopupMenu(mnPopup);
jPanel1.setOpaque(false);
jPanel1.setLayout(new javax.swing.OverlayLayout(jPanel1));
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

jMenu1.setText("File");
jMenuBar1.add(jMenu1);

mnfunktionen.setText("Funktionen");

mnzeichneGarten.setText("Garten anlegen");
mnfunktionen.add(mnzeichneGarten);

mnzeichneRandPflanzen.setText("Random Bepflanzung");
mnfunktionen.add(mnzeichneRandPflanzen);

jMenuBar1.add(mnfunktionen);

setJMenuBar(jMenuBar1);

pack();
}// </editor-fold>//GEN-END:initComponents

/**
* @param args the command line arguments
*/
public static void main(String args[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}
catch (ClassNotFoundException ex)
{
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (InstantiationException ex)
{
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (IllegalAccessException ex)
{
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new GUI().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem1;
private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItem2;
private javax.swing.JMenu mnPflanze1;
private javax.swing.JMenu mnPflanze2;
private javax.swing.JMenu mnPflanze3;
private javax.swing.JPopupMenu mnPopup;
private javax.swing.JMenu mnfunktionen;
private javax.swing.JMenuItem mnzeichneGarten;
private javax.swing.JMenuItem mnzeichneRandPflanzen;
private javax.swing.JRadioButtonMenuItem radiobuttonpfl1;
// End of variables declaration//GEN-END:variables
}

Loading…
Cancel
Save