我有和編輯按鈕,它應該打開一個不同的Jframe,但由於某種原因,它在屏幕上閃爍並消失。我無法弄清楚,也許你們可以。我的刪除按鈕刪除所選行上方的行。該幀是在像250和按下按鈕是行323當按鈕被點擊時,我的Jframe不會保持打開
Button declaration:
btnAdd = new JButton("Add Student");
btnAdd.addActionListener(bh);
btnEdit = new JButton("EDIT");
btnEdit.addActionListener(bh);
btnEdit.setEnabled(false);
btnDelete = new JButton("DELETE");
btnDelete.addActionListener(bh);
btnDelete.setEnabled(false);
btnSort = new JButton("Update");
btnSort.addActionListener(bh);
btnSave = new JButton("SAVE");
btnSave.addActionListener(bh);
btnSave.setActionCommand("Save");
btnAddInput = new JButton("Add Student");
btnAddInput.addActionListener(bh);
btnAddInput.setActionCommand("AddInput");
btnCancel = new JButton("Cancel");
btnCancel.addActionListener(bh);
幀聲明:
frame1 = new JFrame("Edit Student");
frame1.setVisible(false);
frame1.setResizable(false);
frame1.setDefaultCloseOperation(HIDE_ON_CLOSE);
frame1.add(addPanel, BorderLayout.CENTER);
frame1.add(buttonPanel2, BorderLayout.PAGE_END);
frame1.pack();
按鈕處理程序:
類ButtonHandler實現的ActionListener { 公共無效的actionPerformed(ActionEvent的發送){
if (e.getActionCommand().equals("Add Student")) {
txtID.setText("");
txtName.setText("");
txtMajor.setText("");
txtGPA.setText("");
txtCampus.setText("");
txtAddress.setText("");
txtPhone.setText("");
txtEmail.setText("");
txtCurrent.setText("");
txtPast.setText("");
txtFuture.setText("");
txtNotes.setText("");
frame1.setTitle("Add Student data"); // title bar name for add
frame1.setVisible(true);
Student student = new Student(txtID.getText(), txtName.getName(), txtMajor.getText(), txtGPA.getText(), txtCampus.getText(), txtAddress.getText(), txtPhone.getText(),txtEmail.getText(), txtCurrent.getText(), txtPast.getText(), txtFuture.getText(), txtNotes.getText());
al.add(student);
try {
Student.saveSerialized(student, txtID.getText());
} catch (IOException ex) {
Logger.getLogger(IAdvise.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (e.getActionCommand().equals("EDIT")) {
frame1.setVisible(true);
txtID.setText(data[rowIndex][0] + "");
txtName.setText(data[rowIndex][1] + "");
txtMajor.setText(data[rowIndex][2] + "");
txtGPA.setText(data[rowIndex][3] + "");
txtCampus.setText(data[rowIndex][4] + "");
txtAddress.setText(data[rowIndex][5] + "");
txtPhone.setText(data[rowIndex][6] + "");
txtEmail.setText(data[rowIndex][7] + "");
txtCurrent.setText(data[rowIndex][8] + "");
txtPast.setText(data[rowIndex][9] + "");
txtFuture.setText(data[rowIndex][10] + "");
txtNotes.setText(data[rowIndex][11] + "");
txtID.setEditable(false);
frame1.setTitle("Enter Student data");
btnAddInput.setActionCommand("Edit2");
btnAddInput.setText("ACCEPT");
} else if (e.getActionCommand().equals("DELETE")) {
int confirm = JOptionPane.showConfirmDialog(frame, "ARE YOU SURE?", "CONFIRM",
JOptionPane.YES_NO_OPTION);
if (confirm == 0) {
rowIndex = table.getSelectedRow();
rowNumber = 0;
noOfStudents--;
for (int i = 0; i <= 10; i++) {
if (rowIndex != i && i <= noOfStudents) {
data[rowNumber][0] = data[i][0];
data[rowNumber][1] = data[i][1];
data[rowNumber][2] = data[i][2];
data[rowNumber][3] = data[i][3];
data[rowNumber][4] = data[i][4];
data[rowNumber][5] = data[i][5];
data[rowNumber][6] = data[i][6];
data[rowNumber][7] = data[i][7];
data[rowNumber][8] = data[i][8];
data[rowNumber][9] = data[i][9];
data[rowNumber][10] = data[i][10];
data[rowNumber][11] = data[i][11];
rowNumber++;
} else if (rowIndex != i && i > noOfStudents) {
data[rowNumber][0] = "";
data[rowNumber][1] = "";
data[rowNumber][2] = "";
data[rowNumber][3] = "";
data[rowNumber][4] = "";
data[rowNumber][5] = "";
data[rowNumber][6] = "";
data[rowNumber][7] = "";
data[rowNumber][8] = "";
data[rowNumber][9] = "";
data[rowNumber][10] = "";
data[rowNumber][11] = "";
rowNumber++;
}
}
if (noOfStudents == 1000) {
btnAdd.setEnabled(false);
}
else {
btnAdd.setEnabled(true);
}
if (noOfStudents == 0) {
btnDelete.setEnabled(false);
btnEdit.setEnabled(false);
} else {
btnDelete.setEnabled(true);
btnEdit.setEnabled(true);
}
rowIndex = table.getSelectedRow();
if (data[rowIndex][0] == null || data[rowIndex][0] == "") {
btnEdit.setEnabled(false);
btnDelete.setEnabled(false);
} else {
btnEdit.setEnabled(true);
btnDelete.setEnabled(true);
}
table.updateUI();
}
請剪下您的代碼示例。你也提到女巫按鈕。 – robbmj
「編輯」按鈕,對不起,即時新 – DSheehan56