what is my problem - Programmers Heaven

Howdy, Stranger!

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

Categories

what is my problem

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


public class MenuBalloon extends Frame implements ActionListener, WindowListener {

private Balloon myBalloon;
private MenuItem growItem, shrinkItem;
private MenuItem leftItem, rightItem;

public static void main(String[] args) {
Frame f = new MenuBalloon();
f.setSize(200, 200);
f.setVisible(true);
}


public MenuBalloon() {
setTitle("Balloon");
setLayout(new FlowLayout());

MenuBar menuBar = new MenuBar();

Menu sizeMenu = new Menu("Size");

growItem = new MenuItem("Grow");
sizeMenu.add(growItem);
growItem.addActionListener(this);

shrinkItem = new MenuItem("Shrink");
sizeMenu.add(shrinkItem);
shinkItem.addActionListener(this);

menuBar.add(sizeMenu);
Menu moveMenu = new Menu("Move");

leftItem = new MenuItem("Left");
moveMenu.add(leftItem);
leftItem.addActionListener(this);

moveMenu.addSeparator();

rightItem = new MenuItem("Right");
moveMenu.add(rightItem);
rightItem.addActionListener(this);

menuBar.add(moveMenu);
setMenuBar(menuBar);

this.addWindowListener(this);

myBalloon = new Balloon(20, 50, 50);
}


public void actionPerformed(ActionEvent event) {
if (event.getSource() == growItem)
myBalloon.ChangeSize(10);
if (event.getSource() == shrinkItem) {
myBalloon.ChangeSize(-10);
if(event.getSource() == leftItem)
myBalloon.moveLeft();
if(event.getSource() == rightItem)
myBalloon.moveRight();
repaint();
}


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


public void windowClosing(WindowEvent event) {
System.exit(0);
}


public void windowIconified(WindowEvent event) {
}


public void windowOpened(WindowEvent event) {
}


public void windowClosed(WindowEvent event) {
}


public void windowDeiconified(WindowEvent event) {
}


public void windowActivated(WindowEvent event) {
}


public void windowDeactivated(WindowEvent event) {
}
}


class Balloon {

private int diameter;
private int xCoord, yCoord;


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

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

public void moveLeft() {
xCoord = xCoord - 10;
}

public void moveRight() {
xCoord = xCoord + 10;
}

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

illegal start of expression


public void paint(Graphics g) {


the output is here[link=http://www.uploadhouse.com/viewfile.php?id=4832293&PHPSESSID=1a3e0739b15ed9e315d264756834b4f6][/link]

Sign In or Register to comment.