Home > Computer Programming > A basic GUI application in Java

A basic GUI application in Java

January 29, 2014 Leave a comment Go to comments

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.

AppLogic

AppLogic Class

  • 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.

AppLogic

MainForm Class

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

MainForm

SubForm Class

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.

SubForm

BasicApp Class

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

AppLogic

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s