Classes:
Balloon
/*
BalloonMaker.java - Cory Goldfuss - December 4, 2000
Program allows user to create "new" balloons derived the from balloon
class.
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class BalloonMaker extends Applet implements ActionListener, ItemListener
{
private Balloon currentBalloon = new Balloon(10, Color.black); //superclass reference to subclass
private int air;
private boolean boo;
private Color colorList[] = { Color.black, Color.red, Color.blue, Color.green,
Color.pink, Color.cyan, Color.orange, Color.yellow,
Color.gray, Color.magenta };
private String colorNames[] = { "Black", "Red", "Blue", "Green",
"Pink", "Cyan", "Orange", "Yellow",
"Grey", "Magenta" };
public void init()
{
// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
//symantec.itools.lang.Context.setApplet(this);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
//{{INIT_CONTROLS
setLayout(null);
setBackground(java.awt.Color.lightGray);
setSize(530,440);
/* JK Estell colorChoice */
colorChoice = new Choice();
for ( int i = 0; i < colorNames.length; i++ )
colorChoice.addItem( colorNames[i] );
add( colorChoice );
colorChoice.setBounds(10,10,100,50);
airLbl.setText("Air:");
add(airLbl);
airLbl.setFont(new Font("Dialog", Font.BOLD, 14));
airLbl.setBounds(168,24,24,24);
add(airFld);
airFld.setBounds(200,24,108,28);
inflateBtn.setLabel("New Balloon!");
add(inflateBtn);
inflateBtn.setBackground(java.awt.Color.red);
inflateBtn.setFont(new Font("Dialog", Font.BOLD, 13));
inflateBtn.setBounds(360,24,84,36);
inflateBtn.setVisible(false);
//}}
airFld.addActionListener( this );
inflateBtn.addActionListener( this );
colorChoice.addItemListener( this );
}
//{{DECLARE_CONTROLS
java.awt.Choice colorChoice = new java.awt.Choice();
java.awt.Label airLbl = new java.awt.Label();
java.awt.TextField airFld = new java.awt.TextField();
java.awt.Button inflateBtn = new java.awt.Button();
//}}
public void actionPerformed (ActionEvent e){
if (e.getSource() == airFld){
inflateBtn.setVisible(true);
currentBalloon.setAir(Integer.parseInt(e.getActionCommand()));
boo = false;
}
if (e.getSource() == inflateBtn){
currentBalloon = new Balloon( currentBalloon.getAir(), currentBalloon.getColor());
boo = true;
}
repaint();
}
public void itemStateChanged( ItemEvent e ){
if ( e.getSource() == colorChoice ) {
currentBalloon.setColor( colorList[ colorChoice.getSelectedIndex() ] );
}
boo = false;
repaint();
}
public void paint(Graphics g){
g.drawString("Enter the amount of air.", 200,15);
currentBalloon.drawBalloon(g, boo);
}
}