Toggle your browser's Back and Forward buttons to compare the running applet to this code. |
Click here to run a fresh copy of the applet: SimpleApplet4.html |
/** USE EXISTING JAVA CLASSES **/
import java.awt.*;
import java.applet.Applet;
/** EXTEND THE JAVA APPLET CLASS **/
public class SimpleApplet4 extends Applet
{String text = "Java has a population of 107,573,749 (1990).";
public void init()
{setBackground(Color.white);}
// Change the gray background to white.
/** CREATE THE CURRENT FRAME **/
public void paint(Graphics g)
{Font font[] = new Font[4];
// Define and initialize an array
font[0] = new Font("TimesRoman",Font.PLAIN,18);
// (list) of different fonts.
font[1] = new Font("TimesRoman",Font.BOLD,18);
font[2] = new Font("TimesRoman",Font.ITALIC,18);
font[3] = new Font("TimesRoman",Font.BOLD+Font.ITALIC,18);
FontMetrics fontmet[]
= new FontMetrics[4]; //
Define an array of font metrics
int fontht[] = new
int[4];
// and an array of font heights.
int yspacing = size().height;
// Also, initialize the spacing
// between lines.
for (int i = 0; i
< 4; i++)
{fontmet[i]
= getFontMetrics(font[i]);
// Initialize the font metrics.
fontht[i] = fontmet[i].getHeight();
// Initialize the font heights.
yspacing -= fontht[i];
// Compute the spacing between
if ( i = = 3) {yspacing /= 5;}
// lines.
}
Toggle your browser's Back and Forward buttons to compare the running applet to this code. |
Click here to run a fresh copy of the applet: SimpleApplet4.html |