Java Reference
In-Depth Information
18.
Create a new private method (after actionPerformed) called setShipmentProperties that
does the following for each text field:
Retrieves the value of the text field
String method length)
Checks that the length of the value is greater than zero (use the
if (length is not greater than zero)
19.
Define an error message in the msgLbl field stating which field value must be entered
20.
Set an error flag (a boolean variable called isDataEntryError) to true
21.
Create several new private class variables to help with the formatting as follows:
A.
Two new SimpleDateFormat class variables called sdf and stf and assign
SimpleDateFormat objects with the following formats to the variables
MM/dd/yyyy hh:mm a
One new Calendar variable called cal and assign a calendar instance as follows
B.
private Calendar cal = Calendar.getInstance();
Create a Date variable called shipDateTime and assign null to it as follows:
22.
private Date shipDateTime = null ;
Create an int variable called shipHour.
23.
24.
In setShipmentProperties, if the error flag (isDataEntryError) is false, execute the following
source code to retrieve and format the date and time choice field's values, create a
shipment object called ship, and set the shipment object's properties:
shipHour = Integer.parseInt(hourCh.getSelectedItem());
if (aMPMCh.getSelectedItem().equals("PM")&& shipHour < 12){
shipHour = shipHour + 12;
}
if (aMPMCh.getSelectedItem().equals("AM")&&shipHour == 12){
shipHour = 0;
}
cal.set(
Integer.parseInt(yearCh.getSelectedItem()),
Integer.parseInt(monthCh.getSelectedItem()) - 1,
Integer.parseInt(dayCh.getSelectedItem()),
shipHour,
Integer.parseInt(minCh.getSelectedItem())
);
shipDateTime = cal.getTime();
ship = new Shipment(
shipNumTF.getText(),
supplTF.getText(),
sdf.format(shipDateTime),
stf.format(shipDateTime),
empNumTF.getText()
);
Search WWH ::




Custom Search