1 /* 2 * File: DrawableStringTest.java 3 * 4 * Given a string, center the string both vertically and 5 * horizontally in the applet window. 6 * 7 * Copyright: Northeast Parallel Architectures Center 8 * 9 */ 10 11 import java.applet.Applet; 12 import java.awt.*; 13 14 public class DrawableStringTest extends Applet { 15 16 private String s, fontName; 17 private DrawableString drawableString; 18 19 public void init() { 20 21 // Get the "stringToDraw" parameter from the HTML document: 22 s = getParameter( "stringToDraw" ); 23 if ( s == null ) s = "Merry Christmas!"; 24 25 // Get the "font" parameter from the HTML document: 26 fontName = getParameter( "font" ); 27 if ( fontName == null ) fontName = "SansSerif"; 28 29 // Instantiate a DrawableString object: 30 drawableString = new DrawableString( s ); 31 drawableString.setColor( Color.red ); 32 drawableString.setFontName( fontName ); 33 34 // Set the background color of the applet: 35 this.setBackground( Color.cyan ); 36 37 } 38 39 public void paint( Graphics g ) { 40 drawableString.centerDraw( this ); 41 } 42 43 }