In this video, we will create Java AWT Button and TextField. Then, we will handle the button click event using AWT ActionListener and set a greeting text in the text field.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
//Sample 01: Create the Button and Display It Button GreetMe = new Button("Greet Me"); add(GreetMe); 02) //Sample 02: Handle GreetMe Button's Action public void actionPerformed(ActionEvent e) { } 03) //Sample 03: Have TextField as a Class Member TextField txt1; 04) //Sample 03a: Create a text field txt1 = new TextField(25); add(txt1); 05) //Sample 02: Handle GreetMe Button's Action public void actionPerformed(ActionEvent e) { //Sample 04: Handle the Event txt1.setText("Hello, " + txt1.getText()); } 06) //Sample 05: Register with the Listener GreetMe.addActionListener(this); |
Categories: AWT-Tube