Java Reference
In-Depth Information
Example 11•1: GraphicsSampler.java (continued)
if (s2 != null) g.drawString(s2, x1, y1);
}
}
Running the Applet
If you have not yet read Chapter 15, you may not knruow how to run the applet
listed in Example 11-1. All you need to do is include the following <applet> tag in
an HTML file, place the file in the same directory as the GraphicsSampler class
file, and load the HTML file into a web browser:
<applet code="com/davidflanagan/examples/graphics/GraphicsSampler.class"
codebase="../../../.."
width=400 height=400>
</applet>
You'll find this tag in a file named GraphicsSampler.html in this topic's online
example archive.
Note that GraphicsSampler calls the Java 1.1 method getBounds() , so you must
use a browser that supports Java 1.1, such as Netscape Navigator 4.0 or later. You
can also use the appletviewer application that comes with the Java SDK:
% appletviewer GraphicsSampler.html
Fonts
To enhance cross-platform portability, Java 1.0 and 1.1 defined only a handful of
fonts (as we'll see later, Java 1.2 allows you to use any font available on the under-
lying system). In Java 1.0, these fonts were TimesRoman, Helvetica, and Courier.
In Java 1.1, the fonts were given preferred logical names: Serif, SansSerif, and
Monospaced. Each font is available in four styles and any number of sizes. Exam-
ple 11-2 shows the listing of the FontList applet, which displays each of the stan-
dard fonts in each of the available styles. Its output is shown in Figure 11-2.
Example 11•2: FontList.java
package com.davidflanagan.examples.graphics;
import java.applet.*;
import java.awt.*;
/**
* An applet that displays the standard fonts and styles available in Java 1.1
**/
public class FontList extends Applet {
// The available font families
String[] families = {"Serif", // "TimesRoman" in Java 1.0
"SansSerif", // "Helvetica" in Java 1.0
"Monospaced"}; // "Courier" in Java 1.0
// The available font styles and names for each one
int[] styles = {Font.PLAIN, Font.ITALIC, Font.BOLD, Font.ITALIC+Font.BOLD};
String[] stylenames = {"Plain", "Italic", "Bold", "Bold Italic"};
Search WWH ::




Custom Search