Java Reference
In-Depth Information
desktop palette. You can use these colors to make your application match the
desktop color scheme.
Example 11-3 lists the ColorGradient applet, which uses Color objects to produce
the color gradient shown in Figure 11-3. This applet uses applet parameters in the
HTML file to specify the starting and ending colors of the gradient. You can use
the applet with HTML tags like the following:
<applet code="com/davidflanagan/examples/graphics/ColorGradient.class"
codebase="../../../../" width=525 height=150>
<param name="startColor" value="#a06060"> <!-- light red -->
<param name="endColor" value="#ffffff">
<!-- white -->
</applet>
Figur e 11•3. A color gradient
Example 11•3: ColorGradient.java
package com.davidflanagan.examples.graphics;
import java.applet.*;
import java.awt.*;
/** An applet that demonstrates the Color class */
public class ColorGradient extends Applet {
Color startColor, endColor;
// Start and end color of the gradient
Font bigFont;
// A font we'll use
/**
* Get the gradient start and end colors as applet parameter values, and
* parse them using Color.decode(). If they are malformed, use white.
**/
public void init() {
try {
startColor = Color.decode(getParameter("startColor"));
endColor = Color.decode(getParameter("endColor"));
}
catch (NumberFormatException e) {
startColor = endColor = Color.white;
}
Search WWH ::




Custom Search