basically im fairly new to coding in java and im trying to animate some shapes in a drawing window. everything is fine with the code so far in terms of shapes, sizes etc but all i need to know is how to stop my final else if statement going off the edge of the window..ive tried changing the counter but it doesnt seem to be working. cheers
import element.*;
import java.awt.Color;
public class …
{
public static void main(String args[])
{
final int Radius = 40;
DrawingWindow d = new DrawingWindow(500,500); // window is 500 by 500 pixels
int Xpos = 250, Ypos = 250, counter = 0; // size of initial shape
float rect_corner = (float)Radius*2;
while (true)
{
d.hold();
d.clearRect(0,0,500,500);
Rect rect = new Rect(Xpos-Radius,Ypos-Radius,Radius*2,Radius*2);
d.fill(new RoundRect(rect,(int)rect_corner,(int)rect_corner));
// to middle right
if (counter < 125)
{
d.setForeground(Color.red); //change the colour of the shape
Xpos += 1;
}
// to bottom right
else if (counter < 250)
{
d.setForeground(Color.cyan);
Ypos += 1;
}
// to bottom left
else if (counter < 500)
{
if (rect_corner > 0) rect_corner -= 0.5; // changes the shape into a square by moving out the corners
d.setForeground(Color.yellow);
Xpos -= 1;
}
// to top left
else if (counter > 500)
{
if (rect_corner < 0) rect_corner += 1.0;
d.setForeground(Color.GREEN);
Ypos -= 1;
}
counter++;
d.release();
}
}
}