Here is the code of one simple
applet.
But it is not working. It draws a rect. but then stopped.
what happened to it? Can anybody help me?
the files are following.
thanks...
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class ClickMe extends Applet implements MouseListener
{
private Spot spot=null;
private static final int RADIUS=7;
public void init()
{
addMouseListener(this);
}
public void paint(Graphics g)
{
//Draw a black border in a white background
g.setColor(Color.white);
g.fillRect(0,0, getSize().width-1, getSize().height-1);
g.setColor(Color.blue);
g.drawRect(0,0, getSize().width-1, getSize().height-1);
//Draw the spot
g.setColor(Color.red);
if (spot != null)
{
g.fillOval(spot.x - RADIUS,
spot.y - RADIUS,
RADIUS*2, RADIUS*2);
}
}
public void mousePressed(MouseEvent event)
{
if (spot==null)
{
spot=new Spot(RADIUS);
}
spot.x=event.getX();
spot.y=event.getY();
repaint();
}
public void mouseClicked(MouseEvent event) {}
public void mouseReleased(MouseEvent event) {}
public void mouseEntered(MouseEvent event) {}
public void mouseExited(MouseEvent event) {}
}
---------------------
Spot.java
---------------------
public class Spot
{
public int size;
public int x, y;
public Spot(int intSize)
{
size=intSize;
x=-1;
y=-1;
}
---------------------------
myapplet.html
---------------------------
<HTML>
<BODY>
<applet code="ClickMe.class" width="300" height="150">
</applet>
</BODY>
</HTML>
}