Run Error Need Help!

Joined
Mar 9, 2010
Messages
1
Reaction score
0
Hey guys I'm a student and relatively new to java and I'm required to write a gui program for class and im hoping someone can tell me whats wrong with my program. I have finished fixing all the errors for it to successfully compile, but now that its compiled, it wont run. Someone help me please! :D

Heres the code:

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


public class TravelExpenses extends JFrame
{
private JPanel panel;
private JLabel messageLabel;
private JLabel messageLabel2;
private JLabel messageLabel3;
private JLabel messageLabel4;
private JLabel messageLabel5;
private JLabel messageLabel6;
private JLabel messageLabel7;
private JLabel messageLabel8;
private JTextField daysTextField;
private JTextField airfareTextField;
private JTextField carrentalTextField;
private JTextField milesTextField;
private JTextField parkingTextField;
private JTextField taxiTextField;
private JTextField conferenceTextField;
private JTextField lodgingTextField;
private JButton resetButton;
private JButton calcButton;
private final int WINDOW_WIDTH = 310;
private final int WINDOW_HEIGHT = 700;

public TravelExpenses()
{
setTitle("Travel Expense Converter");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}

private void buildPanel()
{

messageLabel = new JLabel("Number Of Days On Trip: ");
daysTextField = new JTextField(10);

messageLabel2 = new JLabel ("Amount Of AirFare: ");
airfareTextField = new JTextField(10);

messageLabel3 = new JLabel ("Car Rental Amount: ");
carrentalTextField = new JTextField(10);

messageLabel4 = new JLabel ("Miles Traveled: ");
milesTextField = new JTextField(10);

messageLabel5 = new JLabel ("Amount Of Parking: ");
parkingTextField = new JTextField(10);

messageLabel6 = new JLabel ("Amount Of Taxi: ");
taxiTextField = new JTextField(10);

messageLabel7 = new JLabel ("Amount Of Conference: ");
conferenceTextField = new JTextField(10);

messageLabel8 = new JLabel ("Amount Of Lodging: ");
lodgingTextField = new JTextField(10);


calcButton = new JButton("Calculate");
calcButton.addActionListener(new CalcButtonListener());

panel = new JPanel();

// Add the label, text field, and button
// components to the panel.
panel.add(messageLabel);
panel.add(daysTextField);
panel.add(messageLabel2);
panel.add(airfareTextField);
panel.add(messageLabel3);
panel.add(carrentalTextField);
panel.add(messageLabel4);
panel.add(milesTextField);
panel.add(messageLabel5);
panel.add(parkingTextField);
panel.add(messageLabel6);
panel.add(taxiTextField);
panel.add(messageLabel7);
panel.add(conferenceTextField);
panel.add(messageLabel8);
panel.add(lodgingTextField);
panel.add(resetButton);
panel.add(calcButton);
}






private class CalcButtonListener implements ActionListener
{

public void actionPerformed(ActionEvent e)
{
String days, airfare, rental, miles, parking, taxi, conference, lodging;
double total, allowable, payback;
final double FOOD=37.0, PARK=10.0, TAXIR=20.0, LODGE=95.0, DRIVE=0.27;

days = daysTextField.getText();
airfare = airfareTextField.getText();
rental = carrentalTextField.getText();
miles = milesTextField.getText();
parking = parkingTextField.getText();
taxi = taxiTextField.getText();
conference = conferenceTextField.getText();
lodging = lodgingTextField.getText();

System.out.println("Reading " + days +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(days));

System.out.println("Reading " + airfare +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(airfare));

System.out.println("Reading " + rental +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(rental));

System.out.println("Reading " + miles +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(miles));

System.out.println("Reading " + parking +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(parking));

System.out.println("Reading " + taxi +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(taxi));

System.out.println("Reading " + conference +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(conference));

System.out.println("Reading " + lodging +
" from the text field.");
System.out.println("Converted value: " +
Double.parseDouble(lodging));


total = Double.parseDouble(days)+Double.parseDouble(airfare)+Double.parseDouble(rental)+Double.parseDouble(miles)+Double.parseDouble(parking)+Double.parseDouble(taxi)+Double.parseDouble(conference)+Double.parseDouble(lodging);
allowable = ((Double.parseDouble(days)*FOOD)+(Double.parseDouble(days)*PARK)+(Double.parseDouble(days)*TAXIR)+(Double.parseDouble(days)*LODGE)+(Double.parseDouble(miles)*DRIVE)+Double.parseDouble(airfare)+Double.parseDouble(rental)+Double.parseDouble(conference));
payback = total-allowable;


JOptionPane.showMessageDialog(null, "Total Expenses: "+total+"\nAllowable Expenses: "+allowable+"\n \nAmount To Be Paid Back: "+payback+"blah");

System.out.println("Ready for the next input.");
}
}


public static void main(String[] args)
{
TravelExpenses te = new TravelExpenses();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top