Java Reference
In-Depth Information
Figure 14.2
HelloSwingApplet displayed in a Web page.
I want to make a few comments about the HelloSwingApplet:
The size of the applet in the colors.html page is 300 pixels wide by 300
pixels high. The content pane of the JApplet is divided into a grid of
two rows and two columns, so each will be of size 150 x 150 pixels.
■■
A JPanel is placed into each grid.
■■
The four JPanel containers are passed into the FourColors listener
object. When the mouse moves over the JApplet, this listener handles
the MouseEvent.
■■
Within the mouseMoved() method of FourColors, some math is done to
calculate which JPanel the mouse is moving over. The color of that
JPanel is changed, while the other JPanel quadrants are made white to
match the background.
■■
Life Cycle of an Applet
When a user views a Web page that contains an applet, the following sequence
of events occurs regarding the life cycle of the applet:
1.
The Web browser downloads the necessary bytecode and JAR file from
the Web server where the code is located. (This Web server is referred to
as the code base.)
Search WWH ::




Custom Search