I have a camping program that has a dialog box where the user inputs the date they are to check in and the date they plan to check out into a text field. Once they press ok on the dialog box, the dates they input should then be viewable in a JTable. Currently, in the date column I get a java.utl.GregorianCalendar[time....etc] when the user presses ok. The other information such as name, days staying, and site number appear okay. Obviously it is not formatting the date correctly, but I'm not sure how to fix it. Here is the code for the Gregorian Calendar in the class DialogCheckInTent:
public GregorianCalendar getDateIn(){
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
GregorianCalendar g = new GregorianCalendar();
try{Date date = df.parse(dateIn.getText());
g.setTime(date);
}
catch (ParseException ex) {
ex.printStackTrace();
}
return g;
}
public GregorianCalendar getCheckOutDate(){
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
GregorianCalendar g = new GregorianCalendar();
try{Date date = df.parse(checkOutTxt.getText());
g.setTime(date);
}
catch (ParseException ex) {
ex.printStackTrace();
}
return g;
}
The above code is used in this method in the GUI when the user pressed okay.
if (pressed == checkInTentItem) {
newTent.clear();
newTent.setVisible(true);
if (model.getRowCount() < 5) {
if (newTent.isOk()) {
String nameReserving = newTent.getNameReserve();
GregorianCalendar checkIn = newTent.getDateIn();
int daysStaying = newTent.getDaysStaying();
GregorianCalendar checkOutOn = newTent.getCheckOutDate();
int siteNumber = newTent.getSiteNumber();
int tenters = newTent.getTenters();
Tent tent = new Tent(nameReserving, checkIn, daysStaying,
checkOutOn, siteNumber, tenters);
model.add(tent);
}
}
else {
JOptionPane.showMessageDialog(frame, "All sites are full.",
" ", JOptionPane.INFORMATION_MESSAGE);
}
}
Everything compiles without a problem, but the date is just not working correctly. How do I fix this?