Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to do with my code

baebae Member Posts: 45
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class PlayBalloon extends Applet implements ActionListener {

private Button grow, shrink;
private Balloon myBalloon;

public void init() {
grow = new Button ("Grow");
add(grow);
grow.addActionListener(this);

grow = new Button ("Shrink");
add(shrink);
grow.addActionListener(this);

myBalloon = new Balloon(20, 50, 50);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == grow)
myBalloon.changeSize(10);
if (event.getSource() == shrink)
myBalloon.changeSize(-10);
repaint();
}

public void paint (Graphics g) {
myBalloon.display(g);
}
}

class Balloon {


private int diameter;
private int xCoord, yCoord;

public Balloon(int initialDiameter, int initialX, int initialY) {
diameter = initialDiameter;
xCoord = initialX;
yCoord = initialY;
}

public void changeSize(int change) {
diameter = diameter + change;
}

public void display(Graphics g) {
g.drawOval(xCoord, yCoord, diameter, diameter);
}
}

can not view the applet in html file

Comments

  • D.O.TD.O.T Member Posts: 4
    I looked at ur code. It wasnt easy to figure out the error.

    You have initialized grow twice instead of initializing shrink

    shrink=new Button("Shrink")
    instead of
    grow= new Button("Shrink");
    otbbtab
Sign In or Register to comment.