From 6e93868830245576c3affb4c1b6a61e3e83326e2 Mon Sep 17 00:00:00 2001 From: Jan <> Date: Fri, 21 Jun 2019 07:59:09 +0200 Subject: [PATCH] . --- Garten/src/garten/model/Beet.java | 14 +++++++------- Garten/src/garten/model/Gaertner.java | 10 ++-------- Garten/src/garten/model/Garten.java | 12 ++++++++---- Garten/src/garten/model/Weg.java | 19 +++++++------------ Garten/src/garten/view/FlaecheBeet.java | 25 +++++++++++++------------ Garten/src/garten/view/FlaecheWeg.java | 17 ++++++++++------- 6 files changed, 47 insertions(+), 50 deletions(-) diff --git a/Garten/src/garten/model/Beet.java b/Garten/src/garten/model/Beet.java index 3c0908e..f667d1b 100644 --- a/Garten/src/garten/model/Beet.java +++ b/Garten/src/garten/model/Beet.java @@ -10,21 +10,21 @@ package garten.model; * * @author Jan */ -class Beet extends Gartenkomponente +public class Beet extends Gartenkomponente { - int positionx2; - int positiony2; + int laenge; + int breite; - Beet(int x, int y,int x2, int y2) + public Beet(int x, int y,int laenge, int breite) { positionx = x; positiony = y; - positionx2 = x2; - positiony2 = y2; + this.laenge = laenge; + this.breite = breite; } public int [] getKoordinaten() { - int[] temp = {positionx,positiony,positionx2,positiony2}; + int[] temp = {positionx,positiony,laenge,breite}; return temp; } diff --git a/Garten/src/garten/model/Gaertner.java b/Garten/src/garten/model/Gaertner.java index 3df6f15..c50643b 100644 --- a/Garten/src/garten/model/Gaertner.java +++ b/Garten/src/garten/model/Gaertner.java @@ -73,20 +73,14 @@ public class Gaertner meinGarten.hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1]-randomwertex[i]-20,randomwertey[j+1] - randomwertey[j]-20); } } - - //Beet * Weg zeichen, muss noch in Garten (geht halt so recht schön) - flbeet.setBeet(randomwertex,randomwertey); - flweg.setWeg(randomwertex,randomwertey); + meinGarten.zeichneWeg(); + meinGarten.zeichneBeete(); for (int i = 0; i<5; i++) { pfl = new Pflanze1(100+(i*50),100+(i*50),3); meinGarten.hinzufuegenPflanze(pfl); } - - meinGarten.zeichnePflanzen(); - //pfl = new Pflanze1(100,100,3); - //pfl2 = new Pflanze1(200,400,4); meinGarten.zeichnePflanzen(); } /* diff --git a/Garten/src/garten/model/Garten.java b/Garten/src/garten/model/Garten.java index 1deebce..99ca324 100644 --- a/Garten/src/garten/model/Garten.java +++ b/Garten/src/garten/model/Garten.java @@ -45,7 +45,11 @@ public class Garten extends Kompositum } public void zeichneBeete() { - + flbeet.zeichneBeete(beete); + } + public void hinzufuegenPflanze(Pflanze pflanze) + { + pflanzen.add(pflanze); } public void zeichnePflanzen() { @@ -57,11 +61,11 @@ public class Garten extends Kompositum Weg neuerWeg = new Weg(sx, sy, ex, ey); wege.add(neuerWeg); } - - public void hinzufuegenPflanze(Pflanze pflanze) + public void zeichneWeg() { - pflanzen.add(pflanze); + flweg.zeichneWeg(wege); } + /* public Pflanze naechstePflanze(int x, int y) { diff --git a/Garten/src/garten/model/Weg.java b/Garten/src/garten/model/Weg.java index 56d0750..57afbaa 100644 --- a/Garten/src/garten/model/Weg.java +++ b/Garten/src/garten/model/Weg.java @@ -10,10 +10,11 @@ package garten.model; * * @author Jan */ -class Weg extends Gartenkomponente +public class Weg extends Gartenkomponente { - int startpositionx,startpositiony,endpositionx,endpositiony; + public int startpositionx,startpositiony,endpositionx,endpositiony; + Weg(int sx, int sy, int ex, int ey) { startpositionx = sx; @@ -22,15 +23,9 @@ class Weg extends Gartenkomponente endpositiony = ey; } - public void zeichnen() - {/* - fill(105,105,105); - strokeWeight(10); - strokeCap(PROJECT); - line(startpositionx,startpositiony,endpositionx,endpositiony); - strokeWeight(1); - noFill(); -*/ + public int [] getKoordinaten() + { + int[] temp = {startpositionx,startpositiony,endpositionx,endpositiony}; + return temp; } - } \ No newline at end of file diff --git a/Garten/src/garten/view/FlaecheBeet.java b/Garten/src/garten/view/FlaecheBeet.java index 2ddbf4b..2d02975 100644 --- a/Garten/src/garten/view/FlaecheBeet.java +++ b/Garten/src/garten/view/FlaecheBeet.java @@ -5,8 +5,10 @@ */ package garten.view; +import garten.model.Beet; import java.awt.Color; import java.awt.Graphics; +import java.util.ArrayList; import javax.swing.JPanel; /** @@ -15,16 +17,16 @@ import javax.swing.JPanel; */ public class FlaecheBeet extends JPanel { - int[] randomwertex; - int[] randomwertey; + int[] temppunkte; Color colorBeet; + private ArrayList beete; public FlaecheBeet() { - randomwertex = new int[4]; - randomwertey = new int[4]; + temppunkte = new int[4]; colorBeet = new Color(153, 102, 51); + beete = new ArrayList<>(); } public void paintComponent(Graphics g) @@ -32,18 +34,17 @@ public class FlaecheBeet extends JPanel super.paintComponent(g); g.setColor(colorBeet); - for (int i = 0; i < randomwertex.length - 1; i++) + for (Beet b : beete) { - for (int j = 0; j < randomwertey.length - 1; j++) - { - g.fillRect(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1] - randomwertex[i] - 20, randomwertey[j + 1] - randomwertey[j] - 20); - } + temppunkte = b.getKoordinaten(); + g.fillRect(temppunkte[0], temppunkte[1], temppunkte[2], temppunkte[3]); } + } - public void setBeet(int[] x, int[] y) //set = automatisch zeichnen + + public void zeichneBeete(ArrayList tempBeet) { - randomwertex = x; - randomwertey = y; + beete.addAll(0, tempBeet); repaint(); } } diff --git a/Garten/src/garten/view/FlaecheWeg.java b/Garten/src/garten/view/FlaecheWeg.java index 1638ef0..739a59a 100644 --- a/Garten/src/garten/view/FlaecheWeg.java +++ b/Garten/src/garten/view/FlaecheWeg.java @@ -5,10 +5,12 @@ */ package garten.view; +import garten.model.Weg; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; +import java.util.ArrayList; import javax.swing.JPanel; /** @@ -20,10 +22,12 @@ public class FlaecheWeg extends JPanel int[] randomwertex; int[] randomwertey; private BasicStroke pinsel; + private ArrayList weg; Color colorWeg; public FlaecheWeg() { + weg = new ArrayList<>(); randomwertex = new int[4]; randomwertey = new int[4]; pinsel = new BasicStroke(6f); @@ -37,17 +41,16 @@ public class FlaecheWeg extends JPanel Graphics2D g2 = (Graphics2D) g; g2.setColor(colorWeg); g2.setStroke(pinsel); - for (int i = 0; i < randomwertex.length; i++) + for(Weg w : weg) { - g2.drawLine(randomwertex[i], randomwertey[0], randomwertex[i], randomwertey[3]); - g2.drawLine(randomwertex[0], randomwertey[i], randomwertex[3], randomwertey[i]); + randomwertex = w.getKoordinaten(); + g2.drawLine(randomwertex[0], randomwertex[1], randomwertex[2], randomwertex[3]); } } - public void setWeg(int[] x, int[] y)//set = automatisch zeichnen - { - randomwertex = x; - randomwertey = y; + public void zeichneWeg(ArrayList tempWeg) + { + weg.addAll(0, tempWeg); repaint(); } }