在向 tableModel 添加信息之前,请帮助我验证(确保)我的所有四个 JOptionPane 文本字段都填充了一些信息。如果某些字段为空,则必须显示警告对话框。并且必须重新打开 JOptionPane 才能让用户完成所有四个字段。
newUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String[] options = {"Ierakstīt", "Atcelt"};
ImageIcon icon = new ImageIcon("C:\\Users\\AdrianP\\Desktop\\kursovaja\\User-48.png");
int n = JOptionPane.showOptionDialog(w, myPanel, "Pievienot jaunu lietotāju", JOptionPane.PLAIN_MESSAGE, 0, icon, options, options[1]);
if (n == 0) {
if (nameField.getText().equals("") && lastNameField.getText().equals("") && groupField.getText().equals("") && idField.getText().equals("")) {
JOptionPane.showMessageDialog(w, "Kļūda!", "Lūdzu, ievadiet datus!", 0, icon);
nameField.setText(null);
lastNameField.setText(null);
idField.setText(null);
groupField.setText(null);
JOptionPane.showOptionDialog(w, myPanel, "Pievienot jaunu lietotāju", JOptionPane.PLAIN_MESSAGE, 0, icon, options, options[1]);
} else {
tableModel.addRow(new Object[] {nameField.getText(), lastNameField.getText(), idField.getText(), groupField.getText()});
nameField.setText(null);
lastNameField.setText(null);
idField.setText(null);
groupField.setText(null);
}
} else {
nameField.setText(null);
lastNameField.setText(null);
idField.setText(null);
groupField.setText(null);
}
}
});