Run Error Need Help!

Discussion in 'Java' started by Sterling, Mar 9, 2010.

  1. Sterling

    Sterling

    Joined:
    Mar 9, 2010
    Messages:
    1
    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();
    }
    }
     
    Sterling, Mar 9, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David
    Replies:
    1
    Views:
    509
    David
    Jul 19, 2004
  2. Nikita A. Visnevski
    Replies:
    10
    Views:
    578
    Nikita A. Visnevski
    Apr 20, 2004
  3. research.gade@gmail.com

    Need help with Run Time Settings in Eclipse "-Djava"

    research.gade@gmail.com, Oct 15, 2006, in forum: Java
    Replies:
    3
    Views:
    1,004
    research.gade@gmail.com
    Oct 15, 2006
  4. iskeletor
    Replies:
    3
    Views:
    366
    Barry Schwarz
    Dec 26, 2006
  5. il-han
    Replies:
    1
    Views:
    408
    il-han
    Feb 13, 2008
Loading...

Share This Page