/* FIle: ChoiceTest.java Author: Chris Johnson johnson@dcs.gla.ac.uk Last modified: 23/10/98 Acknowledgement: This implements an Applet originally developed in D.M. Geary's GraphicJava1.1, The SunSoft Press, Prentice Hall, 1997, page 201-202. I translated it into AWT1.0 so that it could be adapted for a course that only had access to 1.0. Description: Three choices are presented to the user: font; size and style. The font enables them to select between Helvetica, Times etc. The exact nature of this choice is determined by the fonts available on a particular system. The size provides a choice point sizes. The style refers to italics, bold, plain etc. A label is then updated to show what the effect of these different selections would be on a particular piece of text. */ import java.applet.Applet; import java.awt.*; public class ChoiceTest extends Applet{ private FontPanel fontPanel = new FontPanel(this); private Label label = new Label(" ", Label.CENTER); /* Used to display the textual label that illustrates the application of the font, style and size */ public void init() { setLayout(new BorderLayout()); add("North", fontPanel); add("Center", label); } public void start(){ updateLabel(fontPanel.getSelectedFont()); } public void updateLabel(Font font){ label.setText(fullNameOfFont(font)); label.setFont(font); } private String fullNameOfFont(Font font){ String family = font.getFamily(); String style = new String(); switch(font.getStyle()){ case Font.PLAIN: style = " Plain "; break; case Font.BOLD: style = " Bold "; break; case Font.ITALIC: style = " Italic "; break; case Font.BOLD + Font.ITALIC: style = " Bold Italic "; break; } return family + style + Integer.toString(font.getSize()); /* remember that + can be used to concatenate two strings together */ } } class FontPanel extends Panel{ static boolean DEBUG=false; /* prints out debugging messages if true */ private ChoiceTest choiceTest; private Choice familyChoice = new Choice(); /* Helvetica etc */ private Choice styleChoice = new Choice(); /*Bold, Italics etc */ private Choice sizeChoice = new Choice(); /* Point size...*/ public FontPanel(ChoiceTest applet){ choiceTest = applet; populateFonts(); populateStyles(); populateSizes(); add(familyChoice); add(styleChoice); add(sizeChoice); } private void populateFonts(){ String fontNames[] = getToolkit().getFontList(); for(int i=0; i