Java Reference
In-Depth Information
Note
This introduction gives a rough overview of the PDAP subset of AWT only.
Appendix B
contains a
general comparison of the J2SE AWT and the AWT subset contained in PDAP.
Custom Components
Compared to SWING, the component set of AWT is quite limited. Most additional third-party AWT
components probably won't fit to the constraints of the subset contained in the PDA Profile in most
cases. In order to close this gap, it is often necessary to create custom components.
In order to be prepared for this task, you need to recall the main functionality that is provided by a
component:
• Displaying the component on the screen
• Handling user events
In this section, we will start with a passive component not handling user events. Implementing a
progress bar component, we describe all steps necessary to display a custom component on the screen.
After we have created the non-interactive progress bar component, we will implement an image button
capable of handling user events.
The
Component
class is the abstract super class of all non-menu related AWT components. It can be
extended directly to create a customized component necessary for our progress bar and image button
component as well.
The
ProgressBar
should provide a graphical representation of integer values in a bar graph style,
comparable with a non-interactive
Gauge
of the MIDP
lcdui
package.
value in the range from 0 to 100 is stored in the
value
variable. The method
setValue()
is used to
change the state of the
ProgressBar
during application runtime.
In order to create a component that is capable of displaying itself, we need to overwrite the paint
method. The paint method is responsible for drawing the component itself. In the progress bar
paint()
method, we use the given graphic object to draw a progress bar depending on the value variable and the
current size of the component.
Search WWH ::
Custom Search