//File: Circles.java //The following packages are necessary for any applet import java.applet.*; import java.awt.*; //The following package is necessary if we are to have //an interactive applet, one that responds to events import java.awt.event.*; public class Circles extends Applet implements ActionListener { Button circleButton = new Button("New Circle"); public void init() { //add the applet components here add (circleButton); circleButton.addActionListener(this); } //The paint() method is called by the browser whenever the applet must be redrawn public void paint (Graphics g) { Dimension d=getSize(); int w=d.width; int h=d.height; int x,y,radius; radius=25; x = (int) (w * Math.random()); y = (int) (h * Math.random()); g.setColor (Color.red); g.fillOval(x-radius, y-radius, 2*radius, 2*radius); } //The actionPerformed() method from the ActionListener interface must be implemented public void actionPerformed (ActionEvent event) { //Here is where the ActionListener components respond to events repaint(); //calls update() which clears the window, //then calls paint() } }