Java Reference
In-Depth Information
LISTING 2.10
continued
DISPLAY
class, which is part of the
javax.swing
package, and various graphics capabilities
defined in the
java.awt
package. Chapter 3 explores
import
statements further.
A class that defines an applet extends the
JApplet
class, as indicated in the
header line of the class declaration. This process is making use of the object-
oriented concept of inheritance, which we discussed in Chapter 1 and explore
in more detail later in the topic. Applet classes must also be declared as
public
.
The
paint
method is one of several applet methods that have particular sig-
nificance. It is invoked automatically whenever the graphic elements of the applet
need to be painted to the screen, such as when the applet is first run or when
another window that was covering it is moved.
Note that the
paint
method accepts a
Graphics
object as a parameter. A
Graphics
object defines a particular
graphics context
with which we can interact.
The graphics context passed into an applet's
paint
method represents the entire
applet window. Each graphics context has its own coordinate system. In later
examples, we will have multiple components, each with its own graphics context.
A
Graphics
object allows us to draw various shapes using methods such as
drawRect
,
drawOval
,
drawLine
, and
drawString
. The parameters passed to the
drawing methods specify the coordinates and sizes of the shapes to be drawn. We
explore these and other methods that draw shapes in the next section.
Search WWH ::
Custom Search