/** * Private method used when the "Add button is clicked on the dialog box. Either adds the * appointment or spawns an error message if invalid info entered */ private void jButtonAddMouseClicked(java.awt.event.MouseEvent evt) { int startHours = Integer.parseInt((String) jComboBoxStartHours.getSelectedItem()); int startMinutes = Integer.parseInt((String) jComboBoxStartMinutes.getSelectedItem()); int endHours = startHours == 12 ? 1 : startHours + 1; int endMinutes = 0; boolean startPM = false, endPM = false; if (jRadioButtonPM.isSelected()) startPM = true; if (startHours == 11) endPM = true; else endPM = startPM; String startTime = startHours + ":" + String.format("%02d", startMinutes) + " " + (startPM ? "PM" : "AM"); String endTime = endHours + ":" + String.format("%02d", endMinutes) + " " + (endPM ? "PM" : "AM"); int x = startHours + (startPM ? 12 : 0); int start = Integer.parseInt(x + "" + String.format("%02d", startMinutes)); x = endHours + (endPM ? 12 : 0); int end = Integer.parseInt(x + "" + String.format("%02d", endMinutes)); // hours = 9-5 boolean outHours = (startPM && startHours > MyCalendar.endLimit - 1) || (!startPM && startHours < MyCalendar.startLimit); if (outHours || end <= start || !isValidInput(jTextFieldName.getText()) || !isValidInput(jTextFieldPhone.getText())) { // invalid input throw popup EntryErrorDialog error = new EntryErrorDialog(owner, true); error.setVisible(true); } else { Appt newAppt = new Appt( date, jTextFieldName.getText(), jTextFieldPhone.getText(), startTime, endTime, jTextFieldNotes.getText(), uid); if (appointment != null) { if (!newAppt.equals(appointment)) { // delete and create new if edited version is not the same owner.deleteAppt(appointment); if (owner.addAppt(newAppt)) { setVisible(false); } else { ApptFullErrorDialog error = new ApptFullErrorDialog(owner, true); error.setVisible(true); owner.addAppt(appointment); } } } else { if (owner.addAppt(newAppt)) { setVisible(false); } else { ApptFullErrorDialog error = new ApptFullErrorDialog(owner, true); error.setVisible(true); } } } }