learning java AWT EventQs
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class EventQs { private Frame f = new Frame("event test"); private Button ok = new Button("confired"); private TextField tf = new TextField(50); public void init(){ ok.addActionListener(new OkListener()); f.add(tf); f.add(ok, BorderLayout.SOUTH); f.pack(); f.setVisible(true); } class OkListener implements ActionListener{ public void actionPerformed(ActionEvent e){ System.out.println("button be pressed"); tf.setText("hello panzidong"); } } public static void main(String[] args) { new EventQs().init(); } }
output: