import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TravelExpenses extends JPanel
{
private JTextField days; //declaring textfields and labels
private JTextField lodging;
private JTextField airfare;
private JTextField taxiCost;
private JTextField miles;
private JTextField rental;
private JTextField seminarFees;
private JTextField parkingFees;
private JLabel daysL;
private JLabel lodgingL;
private JLabel airfareL;
private JLabel taxiCostL;
private JLabel milesL;
private JLabel rentalL;
private JLabel seminarFeesL;
private JLabel parkingFeesL;
String input;
//int day;
double day, lodge,air,taxi,mile,rentals,sem,park;
/**
Constructorr
*/
public TravelExpenses()
{
setLayout(new GridLayout(8,1 ));
days = new JTextField(4);
lodging = new JTextField(4);
airfare = new JTextField(4);
taxiCost = new JTextField(4);
miles = new JTextField(4);
seminarFees = new JTextField(4);
parkingFees = new JTextField(4);
rental = new JTextField(4);
setBorder(BorderFactory.createTitledBorder("Expenses"));
daysL= new JLabel("Duration of the Trip");
lodgingL = new JLabel("Lodging Cost");
airfareL = new JLabel("Airfare Cost");
taxiCostL = new JLabel("Taxi Expenses");
milesL = new JLabel("Miles Driven");
seminarFeesL= new JLabel("Seminar Fees");
parkingFeesL= new JLabel("Parking Fees");
rentalL = new JLabel("Rental Cost");
add(daysL);
add(days);
add(lodgingL);
add(lodging);
add(airfareL);
add(airfare);
add(taxiCostL);
add(taxiCost);
add(milesL);
add(miles);
add(rentalL);
add(rental);
add(seminarFeesL);
add(seminarFees);
add(parkingFeesL);
add(parkingFees);
input = days.getText();
day = Double.parseDouble(input);
input = lodging.getText();
lodge = Double.parseDouble(input);
input = airfare.getText();
air = Double.parseDouble(input);
input = taxiCost.getText();
taxi = Double.parseDouble(input);
input = miles.getText();
mile = Double.parseDouble(input);
input = rental.getText();
rentals = Double.parseDouble(input);
input = seminarFees.getText();
sem = Double.parseDouble(input);
input = parkingFees.getText();
park = Double.parseDouble(input);
}//end of constructor
public void setValues(int d,double l,double a,double t, double m,double r,double s,double p)
{
day = d;
lodge = l;
air = a;
taxi = t;
mile = m;
rentals = r;
sem = s;
park = p;
}
public double getDays()
{
return day;
}
public double getLodging()
{
return lodge;
}
public double getAirfare()
{
return air;
}
public double getTaxiCost()
{
return taxi;
}
public double getMiles()
{
return mile;
}
public double getRentalCost()
{
return rentals;
}
public double getSeminarFees()
{
return sem;
}
public double getParkingFees()
{
return park;
}
}
Exception in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
at java.lang.Double.parseDouble(Double.java:510)
at TravelExpenses.<init>(TravelExpenses.java:69)
at TravelGUI.<init>(TravelGUI.java:24)
at tets.main(tets.java:5)
I am having problems with this code i can get the window and everything else to work. however, when i try to parse the input from the JTextField for the days i get the above error and i cant figure out whats causing it.
please help
thanks in advance