Results 1 to 1 of 1
Thread: CapitalizeApplet Example
-
CapitalizeApplet Example
Following example is a good one to understand how to use textfields.
Java Code:public class CapitalizeApplet extends Applet { private TextField input; private TextField output; public void init () { // Construct the TextFields this.input = new TextField(40); this.output = new TextField(40); this.output.setEditable(false); Button b = new Button("Capitalize"); // add the button to the layout this.add(input); this.add(b); this.add(output); // specify that action events sent by the // button or the input TextField should be handled // by the same CapitalizerAction object CapitalizerAction ca = new CapitalizerAction(); b.addActionListener(ca); this.input.addActionListener(ca); // notice that ActionEvents produced by output are ignored. } class CapitalizerAction implements ActionListener { public void actionPerformed(ActionEvent ae) { String s = input.getText(); output.setText(s.toUpperCase()); } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks