ok so i have an assignment to do in which i have to have 4 squares moving inwards at each corner of the applet screen one next to another (2 by 2)
i have one of the squares working but dont know how to do the other 3 (positioning)
a little help would be appreciated... this is what i have so far:
import java.awt.*;
public class MovingRects2 extends SimpleAnimationApplet {
public void drawFrame(Graphics g){
int width; //Width of the applet, in pixels.
int height; //Height of the applet, in pixels.
int inset; //Gap between border of applet and a rectangle.
//The inset for the outmost rectangle goes from 0 to 14 then back to
//0, and so on, as the frameNumber varies.
int rectWidth, rectHeight; //the size of one of the rectangles.
width = getWidth(); //Find out the seize of the drawing area.
height = getHeight();
g.setColor(Color.green); //Fill the frame with green
g.fillRect(0, 0,width,height);
g.setColor(Color.black); //Switch color to black.
inset = getFrameNumber() % 15; //Get the inset for the outermost rect
rectWidth = (width - 4*inset - 1)/2; //set size of outermost rect.
rectHeight = (height -4*inset - 1)/2;
while (rectWidth >= 0 && rectHeight >= 0){
g.drawRect(inset,inset,rectWidth,rectHeight);
inset += 15; //Rects are 15 pixels apart.
rectWidth -= 30; //Width decreases by 15 pixels on left and 15 on right.
rectHeight -= 30; //Height decreases by 15 pixels on top and 15 on bottom.
}
}//end drawFrame()
}//end class MovingRects