Java programming course: 17.5 Handling the Add button


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.



Print
×
Stay Informed

When you subscribe, we will send you an e-mail whenever there are new updates on the site.

Related Posts

 

Comments

No comments made yet. Be the first to submit a comment
Monday, 27 October 2025

Captcha Image