* | * | ||||
* @author Jan | * @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; | positionx = x; | ||||
positiony = y; | positiony = y; | ||||
positionx2 = x2; | |||||
positiony2 = y2; | |||||
this.laenge = laenge; | |||||
this.breite = breite; | |||||
} | } | ||||
public int [] getKoordinaten() | public int [] getKoordinaten() | ||||
{ | { | ||||
int[] temp = {positionx,positiony,positionx2,positiony2}; | |||||
int[] temp = {positionx,positiony,laenge,breite}; | |||||
return temp; | return temp; | ||||
} | } | ||||
meinGarten.hinzufuegenBeet(randomwertex[i] + 10, randomwertey[j] + 10, randomwertex[i + 1]-randomwertex[i]-20,randomwertey[j+1] - randomwertey[j]-20); | 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++) | for (int i = 0; i<5; i++) | ||||
{ | { | ||||
pfl = new Pflanze1(100+(i*50),100+(i*50),3); | pfl = new Pflanze1(100+(i*50),100+(i*50),3); | ||||
meinGarten.hinzufuegenPflanze(pfl); | meinGarten.hinzufuegenPflanze(pfl); | ||||
} | } | ||||
meinGarten.zeichnePflanzen(); | |||||
//pfl = new Pflanze1(100,100,3); | |||||
//pfl2 = new Pflanze1(200,400,4); | |||||
meinGarten.zeichnePflanzen(); | meinGarten.zeichnePflanzen(); | ||||
} | } | ||||
/* | /* |
} | } | ||||
public void zeichneBeete() | public void zeichneBeete() | ||||
{ | { | ||||
flbeet.zeichneBeete(beete); | |||||
} | |||||
public void hinzufuegenPflanze(Pflanze pflanze) | |||||
{ | |||||
pflanzen.add(pflanze); | |||||
} | } | ||||
public void zeichnePflanzen() | public void zeichnePflanzen() | ||||
{ | { | ||||
Weg neuerWeg = new Weg(sx, sy, ex, ey); | Weg neuerWeg = new Weg(sx, sy, ex, ey); | ||||
wege.add(neuerWeg); | wege.add(neuerWeg); | ||||
} | } | ||||
public void hinzufuegenPflanze(Pflanze pflanze) | |||||
public void zeichneWeg() | |||||
{ | { | ||||
pflanzen.add(pflanze); | |||||
flweg.zeichneWeg(wege); | |||||
} | } | ||||
/* | /* | ||||
public Pflanze naechstePflanze(int x, int y) | public Pflanze naechstePflanze(int x, int y) | ||||
{ | { |
* | * | ||||
* @author Jan | * @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) | Weg(int sx, int sy, int ex, int ey) | ||||
{ | { | ||||
startpositionx = sx; | startpositionx = sx; | ||||
endpositiony = ey; | 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; | |||||
} | } | ||||
} | } |
*/ | */ | ||||
package garten.view; | package garten.view; | ||||
import garten.model.Beet; | |||||
import java.awt.Color; | import java.awt.Color; | ||||
import java.awt.Graphics; | import java.awt.Graphics; | ||||
import java.util.ArrayList; | |||||
import javax.swing.JPanel; | import javax.swing.JPanel; | ||||
/** | /** | ||||
*/ | */ | ||||
public class FlaecheBeet extends JPanel | public class FlaecheBeet extends JPanel | ||||
{ | { | ||||
int[] randomwertex; | |||||
int[] randomwertey; | |||||
int[] temppunkte; | |||||
Color colorBeet; | Color colorBeet; | ||||
private ArrayList<Beet> beete; | |||||
public FlaecheBeet() | public FlaecheBeet() | ||||
{ | { | ||||
randomwertex = new int[4]; | |||||
randomwertey = new int[4]; | |||||
temppunkte = new int[4]; | |||||
colorBeet = new Color(153, 102, 51); | colorBeet = new Color(153, 102, 51); | ||||
beete = new ArrayList<>(); | |||||
} | } | ||||
public void paintComponent(Graphics g) | public void paintComponent(Graphics g) | ||||
super.paintComponent(g); | super.paintComponent(g); | ||||
g.setColor(colorBeet); | 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<Beet> tempBeet) | |||||
{ | { | ||||
randomwertex = x; | |||||
randomwertey = y; | |||||
beete.addAll(0, tempBeet); | |||||
repaint(); | repaint(); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
package garten.view; | package garten.view; | ||||
import garten.model.Weg; | |||||
import java.awt.BasicStroke; | import java.awt.BasicStroke; | ||||
import java.awt.Color; | import java.awt.Color; | ||||
import java.awt.Graphics; | import java.awt.Graphics; | ||||
import java.awt.Graphics2D; | import java.awt.Graphics2D; | ||||
import java.util.ArrayList; | |||||
import javax.swing.JPanel; | import javax.swing.JPanel; | ||||
/** | /** | ||||
int[] randomwertex; | int[] randomwertex; | ||||
int[] randomwertey; | int[] randomwertey; | ||||
private BasicStroke pinsel; | private BasicStroke pinsel; | ||||
private ArrayList<Weg> weg; | |||||
Color colorWeg; | Color colorWeg; | ||||
public FlaecheWeg() | public FlaecheWeg() | ||||
{ | { | ||||
weg = new ArrayList<>(); | |||||
randomwertex = new int[4]; | randomwertex = new int[4]; | ||||
randomwertey = new int[4]; | randomwertey = new int[4]; | ||||
pinsel = new BasicStroke(6f); | pinsel = new BasicStroke(6f); | ||||
Graphics2D g2 = (Graphics2D) g; | Graphics2D g2 = (Graphics2D) g; | ||||
g2.setColor(colorWeg); | g2.setColor(colorWeg); | ||||
g2.setStroke(pinsel); | 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<Weg> tempWeg) | |||||
{ | |||||
weg.addAll(0, tempWeg); | |||||
repaint(); | repaint(); | ||||
} | } | ||||
} | } |