FileDocCategorySizeDatePackage
aroundWindow.javaAPI DocExample1471Tue Aug 08 17:09:28 BST 2000None

aroundWindow.java

import java.awt.*;		// use existing graphics code
import java.applet.*;	// use existing applet code

// Create an applet and make a pattern by moving a circle around the
// outside of the window.

public class aroundWindow extends Applet	// this is the applet
{
	private int movement = 20 ;	// controls the distance moved in each iteration
	private int circleXPosition ; // the postion of the circle
	private int circleYPosition ;
	
	public void paint(Graphics g)	// this does the drawing
	{
		g.setColor(Color.green) ;
		
		// move circle along the top of the window
		circleYPosition = 0 ;
		for (circleXPosition = 0 ; circleXPosition <= 240 ; circleXPosition += movement)
		{
			g.drawOval(circleXPosition,circleYPosition,60,60) ;
		}
		
		// move circle along the right edge of the window
		circleXPosition = 240 ;
		for (circleYPosition = 0 ; circleYPosition <= 240 ; circleYPosition += movement)
		{
			g.drawOval(circleXPosition,circleYPosition,60,60) ;
		}
		
		// move circle along the bottom of the window
		circleYPosition = 240 ;
		for (circleXPosition = 240 ; circleXPosition >= 0 ; circleXPosition -= movement)
		{
			g.drawOval(circleXPosition,circleYPosition,60,60) ;
		}
		
		// move circle along the left edge of the window
		circleXPosition = 0 ;
		for (circleYPosition = 240 ; circleYPosition > 0 ; circleYPosition -= movement)
		{
			g.drawOval(circleXPosition,circleYPosition,60,60) ;
		}
	}
}