@@ -9,24 +9,29 @@ import garten.view.Fenster; | |||
import garten.view.FlaecheBeet; | |||
import garten.view.FlaechePflanzen; | |||
import garten.view.FlaecheWeg; | |||
import java.awt.event.ActionEvent; | |||
import java.awt.event.ActionListener; | |||
import java.awt.event.MouseEvent; | |||
import java.awt.event.MouseListener; | |||
import java.awt.event.MouseMotionListener; | |||
import java.util.ArrayList; | |||
/** | |||
* | |||
* @author Jan | |||
*/ | |||
public class Gaertner implements MouseListener | |||
public class Gaertner implements MouseMotionListener, MouseListener, | |||
ActionListener | |||
{ | |||
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; | |||
Pflanze1 pfl1; | |||
Pflanze2 pfl2; | |||
Pflanze3 pfl3; | |||
@@ -46,6 +51,7 @@ public class Gaertner implements MouseListener | |||
pflanzen = new ArrayList<>(); | |||
beete = new ArrayList<>(); | |||
pflanzebewegt = false; | |||
//Initialisierung der Wege/Beete | |||
height = fenster.getHeight(); | |||
width = fenster.getWidth(); | |||
@@ -78,16 +84,21 @@ public class Gaertner implements MouseListener | |||
} | |||
meinGarten.zeichneWeg(); | |||
meinGarten.zeichneBeete(); | |||
beete = meinGarten.getBeete(); | |||
meinGarten.randomBepflanzung(); | |||
meinGarten.zeichnePflanzen(); | |||
} | |||
public void registerEvents() | |||
{ | |||
fenster.addMouseListener(this); | |||
fenster.addMouseMotionListener(this); | |||
} | |||
@Override | |||
public void mouseClicked(MouseEvent e) | |||
{ | |||
} | |||
@Override | |||
@@ -98,6 +109,12 @@ public class Gaertner implements MouseListener | |||
@Override | |||
public void mouseReleased(MouseEvent e) | |||
{ | |||
if (pflanzebewegt == true) | |||
{ | |||
meinGarten.setmovePflanze(e); | |||
pflanzebewegt = false; | |||
} | |||
} | |||
@Override | |||
@@ -109,4 +126,26 @@ public class Gaertner implements MouseListener | |||
public void mouseExited(MouseEvent e) | |||
{ | |||
} | |||
@Override | |||
public void actionPerformed(ActionEvent e) | |||
{ | |||
} | |||
@Override | |||
public void mouseDragged(MouseEvent e) | |||
{ | |||
if (pflanzebewegt == false) | |||
{ | |||
if (meinGarten.getmovePflanze(e) != null) | |||
{ | |||
pflanzebewegt = true; | |||
} | |||
} | |||
} | |||
@Override | |||
public void mouseMoved(MouseEvent e) | |||
{ | |||
} | |||
} |
@@ -8,6 +8,7 @@ package garten.model; | |||
import garten.view.FlaecheBeet; | |||
import garten.view.FlaechePflanzen; | |||
import garten.view.FlaecheWeg; | |||
import java.awt.event.MouseEvent; | |||
import java.util.ArrayList; | |||
/** | |||
@@ -23,7 +24,7 @@ public class Garten extends Kompositum | |||
private Pflanze1 pfl1; | |||
private Pflanze2 pfl2; | |||
private Pflanze3 pfl3; | |||
int intmovePflanze; | |||
FlaecheBeet flbeet; | |||
FlaecheWeg flweg; | |||
FlaechePflanzen flpfl; | |||
@@ -111,7 +112,7 @@ public class Garten extends Kompositum | |||
{ | |||
if (versetzt) | |||
{ | |||
tempx = temp[0] +30; | |||
tempx = temp[0]+30; | |||
versetzt = false; | |||
} | |||
else | |||
@@ -130,6 +131,33 @@ public class Garten extends Kompositum | |||
} | |||
} | |||
public Pflanze getmovePflanze(MouseEvent e) | |||
{ | |||
Pflanze diePflanze = null; | |||
int abstand = 30; | |||
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) | |||
{ | |||
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()); | |||
intmovePflanze = i; | |||
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()); | |||
pflanzen.get(intmovePflanze).setPositiony(e.getY()); | |||
pflanzen.get(intmovePflanze).setAlgorithm(); | |||
zeichnePflanzen(); | |||
} | |||
/* | |||
public Pflanze naechstePflanze(int x, int y) | |||
{ | |||
@@ -139,14 +167,12 @@ public class Garten extends Kompositum | |||
{ | |||
if(pflanzen.get(i).getPositionx()-x + pflanzen.get(i).getPositiony()-y < abstand) | |||
{ | |||
print(pflanzen.size()); | |||
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; | |||
@@ -156,19 +182,5 @@ public class Garten extends Kompositum | |||
return null; | |||
} | |||
} | |||
public void zeichnen() | |||
{ | |||
for(int i = 0; i < wege.size(); i++) | |||
{ | |||
wege.get(i).zeichnen(); | |||
} | |||
for(int i = 0; i < beete.size(); i++) | |||
{ | |||
beete.get(i).zeichnen(); | |||
} | |||
}*/ | |||
*/ | |||
} |
@@ -19,5 +19,10 @@ public interface Pflanze | |||
//Position lieferePosition(); | |||
//public void draw(); | |||
public ArrayList<float[]> getPoints(); | |||
public int getPositionx(); | |||
public int getPositiony(); | |||
public void setPositionx(int x); | |||
public void setPositiony(int y); | |||
public void setAlgorithm(); | |||
} |
@@ -85,6 +85,7 @@ public class PflanzeImpl extends JComponent implements Pflanze | |||
} | |||
} | |||
public ArrayList<float[]> getPoints() | |||
{ | |||
return pts; | |||
@@ -114,7 +115,12 @@ public class PflanzeImpl extends JComponent implements Pflanze | |||
{ | |||
return flaeche; | |||
} | |||
public void setAlgorithm() | |||
{ | |||
pts.removeAll(pts); | |||
translateRules(); | |||
} | |||
public void setPosition() | |||
{ | |||
} |
@@ -25,20 +25,15 @@ public class Fenster extends JFrame | |||
popup.add(radioButtonItem); | |||
popup.setLocation(200,200); | |||
popup.setVisible(true); | |||
hauptkiste.add(popup); | |||
JPopupMenu.setDefaultLightWeightPopupEnabled(false); | |||
popup.setVisible(true); | |||
*/ | |||
*/ | |||
this.setTitle("Garten von Paul und Jan"); | |||
this.pack(); | |||
this.setDefaultCloseOperation(EXIT_ON_CLOSE); | |||
this.setSize(900,900); | |||
this.setVisible(true); | |||
} | |||
public void paintComponent() | |||
{ | |||
} | |||
} |