Files in the sample application

Filename

Description

CustomButtonsDemo.java

The application, which includes the entry point that starts the screen, creates and adds each of the UI components, and adds the application to the Event Dispatcher.

CustomButtonField.java

This class provides constructors to create a custom button that is a rectangle, a triangle, an octagon, a rectangle with a fixed width, a rectangle with a fixed width that has a long text label, a rectangle with a full screen width, or a rectangle with a background of a specified color.

This class extends the Field class and overrides the getPreferredHeight() and getPreferredWidth() methods. These methods use the size of the text label to return a height and width respectively to create a custom button that fully encapsulates the text label.

This class also overrides the Field class methods drawFocus(Graphics, boolean), layout(int, int), and paint(Graphics) to render the specific shapes and styles.

PictureBackgroundButtonField.java

This class provides methods to create a custom button with a Bitmap as its background. This class also extends the Field class but, unlike the CustomButtonField class, this class does not implement the DrawStyle interface. This is because this class does not need the text alignment and position constants that the DrawStyle interface provides.

There are two Bitmap objects, (defined within the class, not in the constructor), for when the button is in focus or not in focus. The switching of these Bitmap objects is managed by the overridden onFocus() and onUnfocus() methods from the Field class.

Similar to the CustomButtonField class, the PictureBackgroundButtonField class overrides the getPreferredHeight(), getPreferredWidth(), layout(int, int), and paint(Graphics) methods from the Field class to manage the rendering of the PictureBackgroundButtonField object. However, since the switching of the background image on focus is already managed by the onFocus() and onUnfocus() methods, the drawFocus(Graphics, boolean)does not need to perform any actions.

img/bluescribble.bmp

This is a .bmp file that the PictureBackgroundButtonField object uses as the background when the button is not in focus.

img/pinkscribble.bmp

This is a .bmp file that the PictureBackgroundButtonField object uses as the background when the button is in focus.

Next topic: System requirements
Previous topic: Featured interfaces

Was this information helpful? Send us your comments.