New to JavaProgramming Center
Java Platform Overview |
Getting Started |
Step-by-Step Programming
![]()
Contents
By now you should feel comfortable with objects and methods. You have initialized instances of predefined objects, such as panels and labels, and you have called methods on these objects using a variable, or identifier, and the dot operator. In addition, you have defined your own objects and methods to build GUI components.
In Building an Application, Part 2,
the
Part 3 reinforces these concepts, introduces the
Getting Started
In Part 1, you created the For this part of the tutorial, you need one image and the
Preparing for User Input
Displaying images and labels is useful, but this aspect of an application is passive, only showing information. Most applications also require parts of an application to be active, accepting user input and doing something with the data received. The Java API contains many types of predefined components you can use to collect user data. Here are a few:
When designing an application, consider the type of data to be entered by a user, and how to collect the information. A Dive Log generally contains the name of the diver. In addition, contact information is needed in case of emergency. Other personal data is valuable in a dive log as well, such as the diver's level of formal training. The Diver Data pane accepts input so the diver can enter the following types of information: Personal
Emergency Contact
Formal Training
Remember the Java programming language is all about objects and manipulating data within those objects by calling methods. Listing out your application's data requirements helps you decide what kinds of objects you're going to need to create or initialize. The list above should give you a good idea of the object types you need. Data input for the list of above consists of strings, so use text fields to collect this information. The Java API has a predefined class to create text fields to collect user input. You could also use a text field to request information about training, but that's not appropriate for a Dive Log, since training is not necessarily in a hierarchy. Instead, try check boxes. A diver can check each completed training course. Once the user has entered data into the fields and checked the appropriate boxes, the user needs to be able to submit the information. The most common object used to signal the application to do something with the information entered is a button.
The Java API has a handy class for creating a button component.
You'll learn more about For each item, you need an object to label the object that the user types in, and you need an object to collect the listed data. In other words, for each item above, you'll need at least two objects. The next section shows what is needed and how to handle the Diver Data tabbed pane. Planning the Diver Data PaneTo plan the Diver Data tabbed pane, itemize the objects you need and organize that data at the same time with a sketch. Use either paper and pencil, or a drawing program. For now, list out the label, text field, and check box variable names you'll need, and organize them into a desired layout. This helps you decide:
Once this is completed, you can begin writing the code. The image below illustrates this planning concept:
Notice that:
This makes it easy to see what objects you need to create, therefore which classes you need to initialize, and how you want those object positioned on the pane.
So far there are a total of 22 objects on this pane. You may recall that the
Can you add 22 objects to this Diver Data pane, using the border layout manager?
| ||||||
|
| ||||||||||||