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

    Default how to solve syntax error

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class Rainfall extends Applet implements ActionListener, MouseListener {

    private Table rainData;
    private TextField value;

    public void init() {
    rainData = new Table();

    Label 1 = new Label("Enter number and click component");
    add(1);
    value = new TextField(10);
    add(value);
    value.addActionListener(this);
    addMouseListener(this);
    }

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

    public void actionPerformed(ActionEvent event) {
    int newValue = Integer.parseInt(value.getText());
    rainData.setValue(newValue);
    repaint();
    }

    public void mouseClicked(MouseEvent event) {
    int yCoord = event.getY();
    rainData.selectComponent(yCoord);
    repaint();
    }

    public void mouseReleased(MouseEvent event) {

    }

    public void mousePressed(MouseEvent event) {

    }

    public void mouseEntered(MouseEvent event) {

    }

    public void mouseExited(MouseEvent event) {

    }
    }

    class Table {

    private final int tableSize = 7;
    private int[] rain = new int[tableSize];
    private int index;
    private int newValue;
    private int sum = 0;

    private final int startX = 20;
    private final int startY = 60;
    private final int boxHeight = 20;
    private final int boxWidth = 60;

    public void display(Graghics g) {
    int y = startY;
    for(int s = 0; s < rain.length; s++) {
    g.drawRect(starX, Y, boxWidth, boxHeight);
    g.drawString(Integer.toString(rain[s]), startX, y + boxHeight * 3/4);
    y = y + boxHeight;
    }
    addValues();
    g.drawString("Total rainfall is"+ sum, 100, 100);
    }
    public void selectComponent(int y) {
    index = (y - startY)/boxHeight;
    rain[index] = newValue;
    }

    public void setValue(int value) {
    newValue = value;
    }

    private void addValues() {
    sum = 0;
    for (int s =0; s < rain.length; s++)
    sum = sum + rain[s];
    }
    }

    error line 13 are -----not statement >>> label ----- ; expected
    how to solve

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

  4. #4
    pro85 is offline Member
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    0

    Default

    error is
    Label 1 = new Label("Enter number and click component");

    Label 1

    Label


    before and after the word Label

  5. #5
    Natrix is offline Member
    Join Date
    Mar 2009
    Posts
    40
    Rep Power
    0

    Default

    Label one = new Label("Something"); ?

  6. #6
    pro85 is offline Member
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    0

    Default

    yes, Natrix , u r right.

    Label one = new Label("Something"); is Label 1 = new Label("Enter number and click component");
    same line error

Similar Threads

  1. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 01:19 AM
  2. Can't solve error message while looping
    By BHCluster in forum New To Java
    Replies: 15
    Last Post: 04-22-2008, 11:51 AM
  3. How to solve "No compiler error"?
    By iceman in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 04:37 AM
  4. Help mi solve my error
    By Deon in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 06:26 AM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 04:26 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
  •