Results 1 to 2 of 2
  1. #1
    pro85 is offline Member
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    0

    Default how to c the output

    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);
    }
    }

    applet not run

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Look at the following line of code in your application.

    Java Code:
    add(shrink);
    Where you define the button shrink? I cannot see that.

Similar Threads

  1. Output
    By Twiggy in forum New To Java
    Replies: 14
    Last Post: 12-31-2008, 10:03 AM
  2. What will be output and why
    By huma in forum Threads and Synchronization
    Replies: 4
    Last Post: 06-26-2008, 10:14 PM
  3. Why the output is always zero
    By mehrotra.chitij in forum New To Java
    Replies: 12
    Last Post: 04-25-2008, 04:05 AM
  4. output
    By Camden in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 10:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •