FileDocCategorySizeDatePackage
MovingCircle1.javaAPI DocExample1641Fri Jul 28 15:19:20 BST 2000None

MovingCircle1

public class MovingCircle1 extends Applet

Fields Summary
private int
xCoord
private int
yCoord
private int
diameter
private int
width
private int
depth
private int
xChange
private int
appletWidth
Constructors Summary
Methods Summary
public voidpaint(java.awt.Graphics g)

		// width of the applet window
			

	     // this does the drawing
	

		g.setColor(Color.blue);		// set the pen colour blue
		g.fillOval(xCoord, yCoord, width, depth); // draw the rectangle
		g.drawString("Hello World", xCoord, yCoord + depth + 20); // write the string
											// if the next drawing position would
											// move the ball off the right hand side
											// of the applet window make the xChange
											// negative
											
						// now check that the ball is within the right side 
		if ((xCoord + diameter + xChange) > appletWidth)
			xChange  = -xChange;
			          // now check that the ball is within the bottom
		             
		             // now check that the ball is within the left side
		             
		             //now check that the ball is within the top


						// now change the values held in xCoord and yCoord
		xCoord = xCoord + xChange;		// move in xChange pixels from the left
		yCoord = yCoord + 20;		// move down 20 pixels from the top