Monday, July 11, 2011

Spots

import java.awt.*;

public class Spots extends java.applet.Applet{

final int MaxSpots = 10;
int[] xPositions = new int[10];
int[] yPositions = new int[10];
int currentSpots = 0;

public void init() {
setBackground(Color.black);
}

public boolean mouseDown(Event evt, int x, int y){
if (currentSpots < MaxSpots){
addSpots(x,y);
}
else
{System.out.println("Too Many Spots.....\n");}

return true;
}

void addSpots(int x, int y){
xPositions[currentSpots] = x;
yPositions[currentSpots] = y;
currentSpots++;
repaint();
}

public void paint(Graphics g){
g.setColor(Color.blue);

for(int i=0; i < currentSpots; i++)
{
g.fillOval(xPositions[i] -10, yPositions[i] -10,20,20);
}
}

}

No comments:

Post a Comment