Skip to main content

reached end of file while parsing error

2 replies [Last post]
jlnickymaster
Offline
Joined: 2007-05-02
Points: 0

i am writing a miles per gallon program with actionListerners.

I am at compiling and get the error of "reached end of file while parsing"
I am brand new to Java and hope to become a superwiz in the next 4 years lol
Hope someone can help.

Here is my code:

// Java Document
// action listener and actionEvent

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

public class MPG3 extends Applet implements ActionListener {

//attributes
double milesPerGallon;
int miles; //variable for milage
double gallons; //variable for gallons

Button milesSubmitButton;
Button gallonsSubmitButton;
Label input_label;
TextField input_text;

public void init() {//initialize

//design look to frame
setBackground(Color.blue); // Set background color to blue
setForeground(Color.white); // Set foreground color to white

setLayout(new FlowLayout()); // Set flow Style

// Create input label and text field.

input_label = new Label("Enter Number of Miles: ");//display text
input_text = new TextField(3);
add(input_label);
add(input_text);

// Create the display button.

milesSubmitButton = new Button("Submit Miles");//submit by button
gallonsSubmitButton = new Button("Submit Gallons");
add (milesSubmitButton);
add (gallonsSubmitButton);

// Attach actions to the components
milesSubmitButton.addActionListener(this);
gallonsSubmitButton.addActionListener(this);
}//end init

public void paint( Graphics g)
{ //graphics display for html applet
super.paint( g );

g.drawRect(15,10,270,20);

g.drawString("The Miles Per Gallon calculated is " + milesPerGallon,25,25);
}//end method paint

//perform action on data submitted
public void actionPerformed(ActionEvent evt); {// Method body
if (evt.getSource()==milesSubmitButton)
//miles
{milesEntry = input_text.getText();//get values
miles = Integer.parseInt( milesEntry ); //convert
// Create input label and text field.
input_label = new Label("Enter number of Gallons: ");//display text
input_text = new TextField(3);
add(input_label);
add(input_text);}
else if (evt.getSource()==gallonsSubmitButton) {
gallonsEntry = input_text.getText();//get values
gallons = Double.parseDouble( gallonsEntry); //convert

//calculate mpg
milesPerGallon = miles / gallons; //calculation
}//end else if
}//end class MPG3

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jlnickymaster
Offline
Joined: 2007-05-02
Points: 0

My brackets were not paired. Pfft...blonde.

tarbo
Offline
Joined: 2006-12-18
Points: 0

The compiler was parsing your code and was expecting another token--in this case, likely an ending brace: '}'--but instead reached the end of the stream.

In layman's terms, you're missing a brace to close your class definition. :p