Building the Forward Button
File:
ForwardButton.java
Contents
Overview
The ForwardButton class is a subclass of RolloverButton.
It specifies a series of images that represent the appearance of a "forward" or "next" control.
The image on the right shows the various images used by this button. This class implements a single method, initImages( ) which is declared as abstract in RolloverButton.
Steps to Follow
This class does not import any packages. It uses only the default package java.lang.* and classes in its default package. This class is derived from RolloverButton which we examined earlier.
public class ForwardButton extends RolloverButton
{
protected void initImages( )
{
|
//Initialize images for the ForwardButton
//Insert "ForwardButton initImages"
|
We have only a single method that was defined as an abstract method in RolloverButton. This method specifies the images to be used for this button. Locate the ForwardButton initImages clipping in the ForwardButton folder and drag it directly
below the last line of code shown above. Your code should now look like
this:
public class ForwardButton extends RolloverButton
{
protected void initImages( )
{
//Initialize images for the ForwardButton
//Insert "ForwardButton initImages"
|
addImage("images/FFF.jpg", upImage);
addImage("images/FFFa.jpg", downImage);
addImage("images/FFFb.jpg", rolloverImage);
|
}
}
|
To implement this method, all we need to specify the images to be used, and the identifying string. Now we can really see the benefits of our architecture!
The forward button class is extremely simple. We are benefiting from our pyramid-based component architecture where we place basic functionality into large base classes and then refine behavior in successive classes.
In the next step, we will implement the BackwardButton.
Click here to return to the main
tutorial file.
|