/*
     This program is another example of using the Balloon class.
     The Balloon class has already been defined in the Balloon.java
     file, so we don't need to redefine it again.
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class PlayBalloon5 extends Applet implements ActionListener, AdjustmentListener
{
    private Balloon randomBalloon;
    int xCoord, yCoord, diameter;
    int red, green, blue;

    public void init() {
        randomBalloon = new Balloon(20, 50, 50, 0, 0, 0);
    }

    public void paint(Graphics g) {
        while(true) {
            xCoord = (int) (Math.random()*200)+1;
            yCoord = (int) (Math.random()*200)+1;
            diameter = (int) (Math.random()*50)+1;
            red = (int) (Math.random()*255)+1;
            green = (int) (Math.random()*255)+1;
            blue = (int) (Math.random()*255)+1;
            randomBalloon.move(xCoord, yCoord);
            randomBalloon.changeSize( diameter - randomBalloon.getSize() );
            randomBalloon.changeColor(red, green, blue);
            randomBalloon.display(g);
            for ( int i = 0; i < 100000000; i++) //waste some time
                Math.sqrt(i);
        }
    }

    public void actionPerformed(ActionEvent event) {

        repaint();
    }

    public void adjustmentValueChanged(AdjustmentEvent event) {

        repaint();
    }
}
