//AppletButtonEvent.java import java.applet.*; import java.awt.*; import java.awt.event.*; public class AppletButtonEvent extends Applet implements ActionListener { TextField input,output; public void init() { Label prompt = new Label("input name"); Button btn = new Button("OK"); input = new TextField(6); output = new TextField(20); add(prompt); add(input); add(btn); add(output); btn.addActionListener(this); } public void actionPerformed(ActionEvent e) { output.setText(input.getText()+",Welcome!"); } }
<html> <body> <applet code=AppletButtonEvent.class width=300 height=300></applet> </body> </html>
时间: 2024-12-30 01:06:33