package com.macmillan.nmeyers; import java.applet.*; import java.awt.*; import java.awt.event.*; /* * ShowFonts11: Display available fonts, using JDK1.1 graphics * capabilities. * * Usage: ShowFonts11 [ [...]] * * Author: Nathan Meyers, nmeyers@javalinux.net * $Id: ShowFonts11.java,v 1.2 1999/11/07 23:51:09 nathanm Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * with this program. If not, the license is available from the * GNU project, at http://www.gnu.org. */ public class ShowFonts11 extends Applet { public ShowFonts11() { initialize(null); } public ShowFonts11(String[] altfonts) { if (altfonts.length == 0) altfonts = null; initialize(altfonts); } public void initialize(String[] altfonts) { // Build a scrolled pane containing a collection of labels // showing all of the available fonts String[] fonts = altfonts; if (altfonts == null) fonts = Toolkit.getDefaultToolkit().getFontList(); ScrollPane pane = new ScrollPane(); setLayout(new GridLayout(1, 1)); add(pane); // We'll put our labels in a panel with a gridlayout Panel panel = new Panel(); panel.setLayout(new GridLayout(0, 2)); pane.add(panel); // Start creating and adding labels with 16-point fonts for (int i = 0; i < fonts.length; i++) { String fontname = fonts[i] + "-plain-16"; Label label = new Label(fontname); label.setFont(Font.decode(fontname)); label.setForeground(Color.black); label.setBackground(Color.white); panel.add(label); fontname = fonts[i] + "-bold-16"; label = new Label(fontname); label.setFont(Font.decode(fontname)); label.setForeground(Color.black); label.setBackground(Color.white); panel.add(label); fontname = fonts[i] + "-italic-16"; label = new Label(fontname); label.setFont(Font.decode(fontname)); label.setForeground(Color.black); label.setBackground(Color.white); panel.add(label); fontname = fonts[i] + "-bolditalic-16"; label = new Label(fontname); label.setFont(Font.decode(fontname)); label.setForeground(Color.black); label.setBackground(Color.white); panel.add(label); } } public static void main(String[] argv) { Frame frame = new Frame(); ShowFonts11 api = new ShowFonts11(argv); frame.add(api); frame.pack(); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { System.exit(0); } }); } }