FileDocCategorySizeDatePackage
ChoiceDemo.javaAPI DocExample1482Sun Dec 27 15:20:32 GMT 1998None

ChoiceDemo

public class ChoiceDemo extends Applet
Demonstrate use of Choice; also Font, action(), Event, ...

Fields Summary
Button
b1
Choice
cl
Label
myLabel
Constructors Summary
Methods Summary
private voidApply()

		String item = cl.getSelectedItem();
		myLabel.setText(item);
	
public java.lang.StringgetAppletInfo()
Return information about this applet.

		return "ChoiceDemo Applet, Version 0, Copyright Learning Tree International";
	
public java.lang.String[][]getParameterInfo()
Return list of allowable parameters.

		String param_info[][] = {
			{"fontsize",    "10-20",    "Size of font"},
		};
		return param_info;
	
public voidinit()
init: set a font, initialize UI components.

		setLayout(new FlowLayout());

		String pSize = getParameter("fontsize"); 
		if (pSize == null)
			pSize = "12";
		// System.out.println("Fontsize is " + pSize);
		Font f = new Font("Helvetica", Font.PLAIN, Integer.parseInt(pSize));
		setFont(f);
   
		/* Build the UI */
		add(cl = new Choice()) ;
		cl.setFont(f);	// ignored?
		cl.addItem("Whipping Cream");
		cl.addItem("Icing Sugar");
		cl.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent event) {
				Apply();
			}
		});
		add(b1 = new Button("Apply"));
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				Apply();
			}
		});
		myLabel  = new Label("Please Choose Something", Label.CENTER);
		add(myLabel);