import java.awt.event.*; import java.awt.Graphics; import java.lang.Math; public class Circle extends java.applet.Applet implements MouseListener, MouseMotionListener { int mx, my; public void init() { mx=-1; setSize(500, 500); addMouseListener(this); addMouseMotionListener(this); } public void destroy() { removeMouseListener(this); removeMouseMotionListener(this); } public void paint(Graphics g) { if (mx != -1){ int d=(int)(Math.random()*1000) % (getSize().width - (getSize().width/2)); g.drawOval(mx-(int)(d/2),my-(int)(d/2),d,d); } } /* * Mouse methods */ public void mouseDragged(MouseEvent e) { } public void mouseMoved(MouseEvent e) { /* e.consume(); repaint();*/ } public void mousePressed(MouseEvent e) { int x = e.getX(); mx=x; int y = e.getY(); my=y; e.consume(); requestFocus(); repaint(); } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { // repaint(); } public void mouseExited(MouseEvent e) { // repaint(); } public void mouseClicked(MouseEvent e) { } }