import java.applet.Applet; import java.awt.*; import java.awt.event.*; /** Draw circles centered where the user clicks. * Uses anonymous inner classes. * ********************** public class CircleDrawer4 extends Applet { public void init() { setForeground(Color.blue); addMouseListener (new MouseAdapter() { private int radius = 25; public void mousePressed(MouseEvent event) { Graphics g = getGraphics(); g.fillOval(event.getX()-radius, event.getY()-radius, 2*radius, 2*radius); } }); } } *******************
Applet that uses a anonymous nested class to handle mouse events and draw circles. Variation on third approach to event-handling: using inner classes.
Permanent link to this article: http://bangla.sitestree.com/applet-that-uses-a-anonymous-nested-class-to-handle-mouse-events-and-draw-circles-variation-on-third-approach-to-event-handling-using-inner-classes/