// 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