好吧,即時嘗試從我的數組中刪除一個對象,每個對象都有一個用戶ID,所以數組中的0索引將持有ID爲1的對象。當我刪除對象wih id爲2例如我想刪除數組中的1索引並重做模型並顯示它。所以我希望模型顯示1:胡說,然後3:胡說等留出刪除的文件從數組中刪除,但保持秩序?
private void DeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
// arrays index not working when deleted
int reply = JOptionPane.showConfirmDialog(null, "Are you sure?","Delete Patient: " +
NameTextField.getText(), JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
int Num = Integer.parseInt(IDTextField.getText());
int Num1 = Num--;
for(Patient s: PatientList)
{
if(Num == s.getAccountNumber())
{
PatientList.remove(Num1);
break;
}
}
DefaultListModel PatientListModel = new DefaultListModel();
for(Patient s: PatientList)
{
PatientListModel.addElement(s.getAccountNumber() + "-" + s.getName());
}
PatientJList.setModel(PatientListModel);
//delete procedures for that id
JOptionPane.showMessageDialog(null, "Patient: " + NameTextField.getText() + "
Deleted!");
NameTextField.setText("");
AgeTextField.setText("");
AddressTextField.setText("");
SexGroup.clearSelection();
PhoneTextField.setText("");
IDTextField.setText("");
PatientJList.clearSelection();
}
else {
}
}
而你的問題是?你爲什麼不尊重Java命名約定? – 2013-03-03 17:40:11