Java Reference
In-Depth Information
Directory "CurveApplet 1"
You need an HTML file to run the applet. The contents can be something like:
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code = "CurveApplet.class"
width = "300"
height = "300"
>
</applet>
</center>
</body>
</html>
If you run the applet using appletviewer , you get a window that looks like the one shown in Figure
19-13 .
FIGURE 19-13
How It Works
To display the curves, you need an object of your own class type so that you can implement the paint()
method for it. You define the inner class, CurvePane , for this purpose with JComponent as the base class
so it is a Swing component. You create an object of this class (which is a member of the CurveApplet
class) and add it to the content pane for the applet using its inherited add() method. The layout man-
ager for the content pane is BorderLayout , and the default positioning is BorderLayout.CENTER so the
CurvePane object fills the content pane.
The points defining the quadratic and cubic curves are defined as fields in the CurveApplet class and the
fields that store references to the curve objects are used in the paint() method for the CurvePane class
to display curves. The fields that store points are used in the CurvePane class constructor to create the
 
 
Search WWH ::




Custom Search