Wstawiłem tylko część kodu, już mi zadziałało.
Całość:
public class AddEmployeeDialog extends javax.swing.JDialog {
private DefaultComboBoxModel<Profesion> profesionModel = new DefaultComboBoxModel<>();
private DefaultComboBoxModel<Unit> unitModel = new DefaultComboBoxModel<>();
/**
* @param parent
*/
public AddEmployeeDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
this.profesionModel = new DefaultComboBoxModel<>();
initComponents();
for (Profesion profesion : Profesion.values()) {
profesionModel.addElement(profesion);
}
profesionModel.setSelectedItem(Profesion.ITMAN);
profesionComboBox.setModel(profesionModel);
for (Unit unit : Unit.values()) {
unitModel.addElement(unit);
}
unitModel.setSelectedItem(Unit.CARDIOLOGY);
unitComboBox.setModel(unitModel);
}
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
if (loginTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Login jest pusty");
return;
}
if (surnameTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Surname jest pusty");
return;
}
if (nameTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Nazwisko jest puste");
return;
}
if (peselFormattedTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "PESEL jest pusty");
return;
}
if (dateofbirthFormattedTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Date of birth jest pusty");
return;
}
if (sexTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Sex jest pusty");
return;
}
if (salaryTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Salary jest pusty");
return;
}
if (passwordPasswordField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Hasło jest puste");
return;
}
if (!passwordPasswordField.getText().equals(confirmpasswordPasswordField.getText())) {
JOptionPane.showMessageDialog(this, "Hasło się nie zgadza");
return;
}
if (HospitalOriginalDao.getInstance().selectEmployeeByLogin(loginTextField.getText()) != null) {
JOptionPane.showMessageDialog(this, "Taki uzytkownik istnieje");
return;
}
// dodawanie
String password = HospitalOriginal.toMD5(passwordPasswordField.getText());
Employee employee = new Employee(
surnameTextField.getText(), nameTextField.getText(), peselFormattedTextField.getText(), dateofbirthFormattedTextField.getText(), sexTextField.getText(),
(Profesion) profesionComboBox.getSelectedItem(),
0, (Unit) unitComboBox.getSelectedItem(),
loginTextField.getText(),
password);
HospitalOriginalDao.getInstance().insertEmployee(employee);
this.dispose();
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Bład SQL: " + e.getMessage());
}
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(AddPrescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AddPrescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AddPrescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AddPrescriptionDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
AddEmployeeDialog dialog = new AddEmployeeDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}