public class PlayBalloon extends Applet
class Balloon
1: import java.applet.Applet;
2: import java.awt.*;
3: import java.awt.event.*;
4: public class PlayBalloon extends Applet
5: implements ActionListener {
6: private Button grow, shrink;
7: private Balloon myBalloon;
9: public void init() {
10: grow = new Button ("Grow");
11: add (grow);
12: grow.addActionListener(this);
13:
14: shrink = new Button ("Shrink");
15: add (shrink);
16: shrink.addActionListener(this);
17:
18: myBalloon = new Balloon (20, 50, 50);
19: }
21: public void actionPerformed(ActionEvent event) {
22: if (event.getSource() == grow)
23: myBalloon.changeSize(10);
24: if (event.getSource() == shrink)
25: myBalloon.changeSize(-10);
26: repaint();
27: }
29: public void paint (Graphics g) {
30: myBalloon.display(g);
31: }
32: }
34: class Balloon{
35: private int diameter;
36: private int xCoord, yCoord;
38: public Balloon (int initialDiameter, int initialX, int initialY) {
39: diameter = initialDiameter;
40: xCoord = initialX;
41: yCoord = initialY;
42: }
44: public void changeSize (int change) {
45: diameter = diameter + change;
46: }
48: public void display (Graphics g) {
49: g.drawOval (xCoord, yCoord, diameter, diameter);
50: }
51: }