Login    New User    Forgot Password    Help      

Mouse Spot

Java Tutorials

Example

// mouse tail

/*
<applet code="ev1" width =400 height = 400 >
</applet>
*/

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Event;

public class ev3 extends java.applet.Applet
{
final int MAXSPOTS = 10;
int xspots[] = new int[MAXSPOTS];
int yspots[] = new int[MAXSPOTS];
int currspots = 0;
public void init()
{
setBackground(Color.white);
}

public boolean mouseDown(Event evt, int x, int y)
{
if (currspots < MAXSPOTS)
{
addspot(x,y);
return true;
}
else
{
System.out.println("Too many spots.");
return false;
}
}

void addspot(int x,int y)
{
xspots[currspots] = x;
yspots[currspots] = y;
currspots++;
repaint();
}

public void paint(Graphics g)
{
g.setColor(Color.blue);
for (int i = 0; i < currspots; i++)
{
g.fillOval(xspots[i] - 10, yspots[i] - 10, 20, 20);
}
}
}

Output

Output in applet

Java Tutorials