Academic Java    Java Tutorial  >  Applets  >  drawString()

drawString() Example

Java drawString EXAMPLE output The second and third parameters of drawString() are the coordinates of the baseline of the leftmost character.

The next example below shows how to use the FontMetrics class to determine a font's height.
// drawString() Example
import java.awt.*;
import javax.swing.*;

class DrawStringExample extends JApplet {

   @Override public void paint(Graphics g) {
      super.paint(g);
      g.drawString("the past is a foreign country", 60, 40);
      g.drawString("they do things differently there", 60, 60);
   }
}


* drawString() Examples