|
|
|
|
|
|
SolutionDownload LabeledChoiceTest source code.HTML Interface to Applet<APPLET CODEBASE="/applets/magelang/AWT-Training/classes/" CODE="LabeledChoiceTest.class" WIDTH=300 HEIGHT=40 ALIGN=CENTER></APPLET> Java Codeimport java.awt.*; public class LabeledChoiceTest extends java.applet.Applet { public void init() { LabeledChoice test = new LabeledChoice("Test"); add(test); } } /** * Component containing both a Label and a Choice */ class LabeledChoice extends FormElement { protected Choice choice; protected String label = "Payment Method"; public LabeledChoice(String label) { this.label = label; setLayout(new BorderLayout(5,0)); choice = new Choice(); choice.addItem("American Express"); choice.addItem("Master Card"); choice.addItem("Visa"); choice.addItem("Cash"); choice.addItem("Check"); add("West", new Label(label, Label.LEFT)); add("Center", choice); } /** * Return a text representation of this field. * This method is required by the FormElement interface. * @return String the selected text */ public String getContents() { return label + " " + choice.getSelectedItem(); } } |