ChoiceDemopublic class ChoiceDemo extends Applet Demonstrate use of Choice; also Font, action(), Event, ... |
Fields Summary |
---|
Button | b1 | Choice | cl | Label | myLabel |
Methods Summary |
---|
private void | Apply()
String item = cl.getSelectedItem();
myLabel.setText(item);
| public java.lang.String | getAppletInfo()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 void | init()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);
|
|