Handling the Add button
All that remains now is to write some code for the Add button to enable the user to switch from "change" mode back into "add" mode. Go to the Design view of AnimalPanel and double-click the Add button to generate its addButtonActionPerformed() method. All it needs to do is invoke clearAnimal() on the animalEditor instance and clear any selections in the tree:
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
animalEditor.clearAnimal();
animalTree.getSelectionModel().clearSelection();
}
That completes the coding for the animal panels, and you should now be able to add, change and remove as many animals as you wish.
Comments