import java.awt.font.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DrawText extends JPanel { Font font1, font2, font3; public static void main(String[] args) { JFrame f = new JFrame("DrawText"); f.setContentPane(new DrawText()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public DrawText() { //The following line does not seem to affect the program in //any sence, yet it has to be there. GraphicsEnvironment.getLocalGraphicsEnvironment(). getAvailableFontFamilyNames(); font1 = new Font("DialogInput", Font.BOLD | Font.ITALIC, 40); font2 = new Font("Disney Print", Font.PLAIN, 18); font3 = new Font("Bookman Old Style", Font.PLAIN, 30); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout1 = new TextLayout("This is a string", font1, frc); TextLayout layout2 = new TextLayout("This is a string", font2, frc); TextLayout layout3 = new TextLayout("This is a string", font3, frc); layout1.draw(g2, 10, 30); layout2.draw(g2, 10, 100); layout3.draw(g2, 10, 200); } }