import java.awt.*;
import java.awt.event.*;
public class BullsEyeApplet extends java.applet.Applet {
public void init() {
setLayout( new BorderLayout() );
add( "Center", new BullsEyeComponent() );
}
}
class BullsEyeComponent extends Component {
final int RADIUS=20, RINGS=6;
Point point = new Point();
BullsEyeComponent() {
addMouseMotionListener( new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e) {
point = e.getPoint();
repaint();
}
} );
}
public void paint( Graphics g ) {
for (int i=0; i<RINGS; i++) {
int r = RADIUS - RADIUS/RINGS*i;
g.setColor( (i%2 != 0)? Color.red : Color.black );
g.fillOval( point.x - r, point.y - r, r*2, r*2 );
}
}
}
|