Hi, the following code shows my image moving around the screen but I cannot seem to stop it from hitting the edge of the panel. Can anyone add to the end of the code... much appreciated
import javax.swing.JPanel;
import java.awt.Graphics;
class robotpanel extends JPanel
{
private robot ted;
private Thread robothread;
public robotpanel()
{
ted=new robot(this);
robothread = new Thread(ted);
robothread.start();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
System.out.println(this.getWidth()+" " +this.getHeight());
g.fillRect(ted.getX(),ted.getY(),20,20);
}
}
^^^ I need to add the code at the end to stop "ted" hitting the edge. Please advise. Cheers