Screenshot of the application
The main form just has a list of words and a button. When you press the button a subform pops up with a text field for you to enter a new word. When you enter a word, it is added to the list on the main form.
The code in this project can be adapted to your needs. It shows you how to:
- Separate the interface from the logic of the program
- Maintain and add to a list of objects (in this case strings)
- Pop out a subform and have it pass information back to the main form
- Update a listbox in the UI from the back-end logic
You will need all of these skills when you develop your own applications.
- Has a way of holding a list of strings
- Has a way of keeping count of how many strings there are
- Can accept new strings and add them to the list
- Can return the list of strings
Note: This is not a UI class. It knows nothing about the UI.
This is the main form. Look principally at the button press code buttonActionPerformed. It:
- instantiates and displays the subform
- gets the text entered into the subform
- asks the applogic to add the text
- asks the applogic for the new list so it can update its listbox
This is the subform. It allows you to enter a new word. Note particularly how we had to code a new method called getText() to allow the subform to give its text back to the parent.
This is the entry point to the application. It:
- instantiates the application logic
- instantiates the main form (giving it the handle to the application logic)
- sets the main form to visible