//ChoiceDemo.java //Illustrates use of the Choice component //Andy Harris, 05/00 import java.awt.*; import java.applet.*; import java.awt.event.*; public class ChoiceDemo extends Applet implements ItemListener{ Label lblOutput = new Label("Sample Text"); Choice chcFont = new Choice(); Panel pnlChoice = new Panel(); public void init(){ setLayout(new BorderLayout()); add (lblOutput, BorderLayout.CENTER); lblOutput.setAlignment(Label.CENTER); lblOutput.setFont(new Font("Serif", Font.PLAIN, 20)); pnlChoice.setLayout(new FlowLayout()); pnlChoice.add(chcFont); add(pnlChoice, BorderLayout.SOUTH); //add the font choices chcFont.add("Serif"); chcFont.add("SansSerif"); chcFont.add("Monospaced"); chcFont.add("Dialog"); chcFont.add("DialogInput"); chcFont.addItemListener(this); } // end init public void itemStateChanged(ItemEvent e){ String fontName = chcFont.getSelectedItem(); lblOutput.setFont(new Font(fontName, Font.PLAIN, 20)); } // end itemStateChanged } // end class def