import garten.view.FlaecheBeet; | import garten.view.FlaecheBeet; | ||||
import garten.view.FlaechePflanzen; | import garten.view.FlaechePflanzen; | ||||
import garten.view.FlaecheWeg; | import garten.view.FlaecheWeg; | ||||
import java.awt.event.ActionEvent; | |||||
import java.awt.event.ActionListener; | |||||
import java.awt.event.MouseEvent; | import java.awt.event.MouseEvent; | ||||
import java.awt.event.MouseListener; | import java.awt.event.MouseListener; | ||||
import java.awt.event.MouseMotionListener; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
/** | /** | ||||
* | * | ||||
* @author Jan | * @author Jan | ||||
*/ | */ | ||||
public class Gaertner implements MouseListener | |||||
public class Gaertner implements MouseMotionListener, MouseListener, | |||||
ActionListener | |||||
{ | { | ||||
private Garten meinGarten; | private Garten meinGarten; | ||||
private Fenster fenster; | private Fenster fenster; | ||||
private FlaecheBeet flbeet; | private FlaecheBeet flbeet; | ||||
private FlaecheWeg flweg; | private FlaecheWeg flweg; | ||||
private FlaechePflanzen flpfl; | private FlaechePflanzen flpfl; | ||||
private boolean pflanzebewegt; | |||||
private ArrayList<Pflanze> pflanzen; | private ArrayList<Pflanze> pflanzen; | ||||
private ArrayList<Beet> beete; | private ArrayList<Beet> beete; | ||||
Pflanze1 pfl1; | Pflanze1 pfl1; | ||||
Pflanze2 pfl2; | Pflanze2 pfl2; | ||||
Pflanze3 pfl3; | Pflanze3 pfl3; | ||||
pflanzen = new ArrayList<>(); | pflanzen = new ArrayList<>(); | ||||
beete = new ArrayList<>(); | beete = new ArrayList<>(); | ||||
pflanzebewegt = false; | |||||
//Initialisierung der Wege/Beete | //Initialisierung der Wege/Beete | ||||
height = fenster.getHeight(); | height = fenster.getHeight(); | ||||
width = fenster.getWidth(); | width = fenster.getWidth(); | ||||
} | } | ||||
meinGarten.zeichneWeg(); | meinGarten.zeichneWeg(); | ||||
meinGarten.zeichneBeete(); | meinGarten.zeichneBeete(); | ||||
beete = meinGarten.getBeete(); | |||||
meinGarten.randomBepflanzung(); | meinGarten.randomBepflanzung(); | ||||
meinGarten.zeichnePflanzen(); | meinGarten.zeichnePflanzen(); | ||||
} | |||||
public void registerEvents() | |||||
{ | |||||
fenster.addMouseListener(this); | |||||
fenster.addMouseMotionListener(this); | |||||
} | } | ||||
@Override | @Override | ||||
public void mouseClicked(MouseEvent e) | public void mouseClicked(MouseEvent e) | ||||
{ | { | ||||
} | } | ||||
@Override | @Override | ||||
@Override | @Override | ||||
public void mouseReleased(MouseEvent e) | public void mouseReleased(MouseEvent e) | ||||
{ | { | ||||
if (pflanzebewegt == true) | |||||
{ | |||||
meinGarten.setmovePflanze(e); | |||||
pflanzebewegt = false; | |||||
} | |||||
} | } | ||||
@Override | @Override | ||||
public void mouseExited(MouseEvent e) | 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) | |||||
{ | |||||
} | |||||
} | } |
import garten.view.FlaecheBeet; | import garten.view.FlaecheBeet; | ||||
import garten.view.FlaechePflanzen; | import garten.view.FlaechePflanzen; | ||||
import garten.view.FlaecheWeg; | import garten.view.FlaecheWeg; | ||||
import java.awt.event.MouseEvent; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
/** | /** | ||||
private Pflanze1 pfl1; | private Pflanze1 pfl1; | ||||
private Pflanze2 pfl2; | private Pflanze2 pfl2; | ||||
private Pflanze3 pfl3; | private Pflanze3 pfl3; | ||||
int intmovePflanze; | |||||
FlaecheBeet flbeet; | FlaecheBeet flbeet; | ||||
FlaecheWeg flweg; | FlaecheWeg flweg; | ||||
FlaechePflanzen flpfl; | FlaechePflanzen flpfl; | ||||
{ | { | ||||
if (versetzt) | if (versetzt) | ||||
{ | { | ||||
tempx = temp[0] +30; | |||||
tempx = temp[0]+30; | |||||
versetzt = false; | versetzt = false; | ||||
} | } | ||||
else | else | ||||
} | } | ||||
} | } | ||||
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) | public Pflanze naechstePflanze(int x, int y) | ||||
{ | { | ||||
{ | { | ||||
if(pflanzen.get(i).getPositionx()-x + pflanzen.get(i).getPositiony()-y < abstand) | if(pflanzen.get(i).getPositionx()-x + pflanzen.get(i).getPositiony()-y < abstand) | ||||
{ | { | ||||
print(pflanzen.size()); | |||||
diePflanze = pflanzen.get(i); | diePflanze = pflanzen.get(i); | ||||
abstand = Math.abs(x-pflanzen.get(i).getPositionx()) + Math.abs(y-pflanzen.get(i).getPositiony()) ; | abstand = Math.abs(x-pflanzen.get(i).getPositionx()) + Math.abs(y-pflanzen.get(i).getPositiony()) ; | ||||
print(pflanzen.get(i).getPositionx()); | print(pflanzen.get(i).getPositionx()); | ||||
print(pflanzen.get(i).getPositiony()); | print(pflanzen.get(i).getPositiony()); | ||||
} | } | ||||
} | } | ||||
if(abstand < 20) | if(abstand < 20) | ||||
{ | { | ||||
return diePflanze; | return diePflanze; | ||||
return null; | 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(); | |||||
} | |||||
}*/ | |||||
*/ | |||||
} | } |
//Position lieferePosition(); | //Position lieferePosition(); | ||||
//public void draw(); | //public void draw(); | ||||
public ArrayList<float[]> getPoints(); | public ArrayList<float[]> getPoints(); | ||||
public int getPositionx(); | |||||
public int getPositiony(); | |||||
public void setPositionx(int x); | |||||
public void setPositiony(int y); | |||||
public void setAlgorithm(); | |||||
} | } |
} | } | ||||
} | } | ||||
public ArrayList<float[]> getPoints() | public ArrayList<float[]> getPoints() | ||||
{ | { | ||||
return pts; | return pts; | ||||
{ | { | ||||
return flaeche; | return flaeche; | ||||
} | } | ||||
public void setAlgorithm() | |||||
{ | |||||
pts.removeAll(pts); | |||||
translateRules(); | |||||
} | |||||
public void setPosition() | public void setPosition() | ||||
{ | { | ||||
} | } |
popup.add(radioButtonItem); | popup.add(radioButtonItem); | ||||
popup.setLocation(200,200); | popup.setLocation(200,200); | ||||
popup.setVisible(true); | popup.setVisible(true); | ||||
hauptkiste.add(popup); | |||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false); | JPopupMenu.setDefaultLightWeightPopupEnabled(false); | ||||
popup.setVisible(true); | popup.setVisible(true); | ||||
*/ | |||||
*/ | |||||
this.setTitle("Garten von Paul und Jan"); | this.setTitle("Garten von Paul und Jan"); | ||||
this.pack(); | this.pack(); | ||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE); | this.setDefaultCloseOperation(EXIT_ON_CLOSE); | ||||
this.setSize(900,900); | this.setSize(900,900); | ||||
this.setVisible(true); | this.setVisible(true); | ||||
} | } | ||||
public void paintComponent() | |||||
{ | |||||
} | |||||
} | } |