Hallo Leute,
so ihr seit jetzt meine letzte Hoffnung. Nach 2 Wochen und ca. 40 h Bitte ich um eure Hilfe.
Ich soll auf einem fixen Floor Roboter animieren und dieses auf bestimmte positionen fahren lassen. Das Node und die Routenberechnung funktionieren wunderbar, aber ich schaffe es nicht das der Roboter auf meinem Factory Floor fährt.
Ich erzeuge zuerste ein JFrame und in die Content Pane zeichne ich dann zuerst den Floor und wenn ein Roboter instanziert wird soll er auch auf das JFrame: Bitte schaut euch die beiden CODES an - ihr würdet mir echt helfen wenn ihr mir sagen könntet wie ich das lösen kann:
Momentan fährt der Roboter zwar, aber der BlueFloor wird dann übermalt und er soll aber fix bleiben
!
zuerst der CODE der GUI:
Hier die Klasse für die Roboter:
Das GUI wird in der Main Methode instanziert und wenn der Befehl für einen Roboter eigegeben wird, wird die GUI - Methode addRobot aufgerufen! Der Roboter fährt zwar, aber meine Factory wird übermalt.
Bitte um Hilfe!!
Sg Rudi
[/code]
so ihr seit jetzt meine letzte Hoffnung. Nach 2 Wochen und ca. 40 h Bitte ich um eure Hilfe.
Ich soll auf einem fixen Floor Roboter animieren und dieses auf bestimmte positionen fahren lassen. Das Node und die Routenberechnung funktionieren wunderbar, aber ich schaffe es nicht das der Roboter auf meinem Factory Floor fährt.
Ich erzeuge zuerste ein JFrame und in die Content Pane zeichne ich dann zuerst den Floor und wenn ein Roboter instanziert wird soll er auch auf das JFrame: Bitte schaut euch die beiden CODES an - ihr würdet mir echt helfen wenn ihr mir sagen könntet wie ich das lösen kann:
Momentan fährt der Roboter zwar, aber der BlueFloor wird dann übermalt und er soll aber fix bleiben
!
zuerst der CODE der GUI:
Code:
public class GUI extends JFrame{
public Container c;
Graphics g;
public GUI(){
setResizable(false);
setSize(660,450);
setTitle("BlueFrame");
setLocation(500,50);
setBackground(Color.white);
c = getContentPane();
c.setVisible(true);
c.add(new BlueFloor());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void addRobot(Robots robot, Object[] array, int speed)
{ robot.setXY(array);
robot.setSpeed(speed);
c.add(robot);
c.setVisible(true);
robot.startThread();
public class BlueFloor extends JPanel
{
public void paintComponent(Graphics g)
{
path.NodePath path = new path.NodePath();
path.getMachineNames();
String[] machines;
machines = path.getMachineNames();
g.drawRect(20, 30, 600, 350);
g.setFont(new Font("Arial", Font.BOLD, 17));
g.drawString("G1", 128, 28);
g.drawString("G2", 528, 28);
g.drawString("G3", 28, 128);
g.drawString("G4", 590, 128);
g.drawString("G5", 28, 128+150);
g.drawString("G6", 590, 128+150);
g.drawString("G7", 128, 378);
g.drawString("G8", 528, 128+250);...........
Hier die Klasse für die Roboter:
Code:
public class Robots extends JPanel implements Runnable {
private static Integer countId = new Integer(0);
private Integer id;
private int xPos;
private int yPos;
private int finalxPos;
private int finalyPos;
private int speed = 50 ;
private int xoldPos;
private int yoldPos;
private int addx = 2;
private int addy = 3;
private int counter;
private Object[] move;
public Thread thr;
private boolean busy = false;
Graphics r;
String msa;
//Konstruktor für Starposition
public Robots(Object[] array, int speed)
{
move = array;
xPos=(Integer)move[0];
yPos=(Integer)move[1];
id = countId++;
if(speed != 0)
{
this.speed = 50-this.speed*5;
}
msa = "speed:"+speed+"mm/s";
}
public Robots()
{
id = countId++;
}
void changeColor(int x,int y,Graphics a){
a.setColor(Color.blue);
a.fillOval(x, y, 10, 10);}
//sobald Roboter instanziert wird kann er auch gezeichnet werden
public void paint (Graphics r)
{
if(xPos>1&&yPos>1){
if(xPos<599&&yPos<349){
r.setColor(Color.blue);
r.fillOval(xPos+20, yPos+30, 20, 20);
r.setColor(Color.white);
String a = "R";
r.drawString(a, xPos+25, yPos+45);
r.setColor(Color.blue);
//r.drawString(msa, xPos+10, yPos+28);
}
}
}
//Threadsteuerung:
//-------------------------------------------------------------------------------
public void startThread()
{
thr = new Thread(this);
thr.start();
}
public void run ()
{
busy = true;
xPos=(Integer)move[0];
yPos=(Integer)move[1];
addx = 2;
addy = 3;
do{
finalxPos = (Integer) move[addx];
finalyPos = (Integer) move[addy];
do{
try {Thread.sleep (speed);}
catch (InterruptedException e){}
if(finalxPos != xPos)
{
if(xPos < finalxPos)
{
xPos++;
}
else
{
xPos--;
}
}
else
{
if(yPos < finalyPos)
{
yPos++;
}
else
{
yPos--;
}
}
revalidate();
}
while(xPos!=finalxPos || yPos!=finalyPos);
addx = addx+2;
addy = addy+2;
}while(addy<move.length);
busy = false;
thr.stop();
lastMessage();
}
Das GUI wird in der Main Methode instanziert und wenn der Befehl für einen Roboter eigegeben wird, wird die GUI - Methode addRobot aufgerufen! Der Roboter fährt zwar, aber meine Factory wird übermalt.
Bitte um Hilfe!!
Sg Rudi
[/code]