Java Reference
In-Depth Information
When the CommandButton class is developed, it could define these features:
The text displayed on the button
n
The size of the button
n
Aspects of its appearance, such as whether it has a 3D shadow
n
The CommandButton class also could define how a button behaves, deciding the following
things:
Whether the button requires a single click or a double-click
n
Whether it should ignore mouse clicks entirely
n
What it does when successfully clicked
n
After you define the CommandButton class, you can create instances of that button—in
other words, CommandButton objects. The objects all take on the basic features of a click-
able button as defined by the class, but each one could have a different appearance and
slightly different behavior depending on what you need that object to do.
By creating a CommandButton class, you don't have to keep rewriting the code for each
command button that you want to use in your programs. In addition, you can reuse the
CommandButton class to create different kinds of buttons as you need them, both in this
program and in others.
NOTE
One of Java's standard classes, javax.swing.JButton , encom-
passes all the functionality of this hypothetical CommandButton
example and more. You get a chance to work with it during Day 9,
“Working with Swing.”
When you write a Java program, you design and construct a set of classes. When your
program runs, objects are instantiated from those classes and used as needed. Your task
as a Java programmer is to create the right set of classes to accomplish what your pro-
gram needs to accomplish.
Fortunately, you don't have to start from scratch. The Java language includes thousands
of classes that implement most of the functionality you will need. These classes are
called the Java class library, and they are installed along with a development tool such as
the JDK.
Search WWH ::




Custom Search