📄 texteventdemo.java
字号:
import java.awt.*;import java.awt.event.*;public class TextEventDemo extends Frame { private TextField tf1, tf2; public TextEventDemo() {/* A TextField is created and placed on a Frame. It registers *//* a TextListener. A second TextField is used to reflect *//* changes in the text contained by the first TextField. */ tf1 = new TextField(25); tf1.addTextListener(new TextEventHandler()); tf2 = new TextField(25); tf2.setEditable(false); Panel panel = new Panel(); panel.add(tf1); add(panel, BorderLayout.NORTH); add(tf2, BorderLayout.SOUTH); addWindowListener(new WinAdapter()); setBounds(100, 100, 300, 200); setVisible(true); }/* The TextListener is implemented as an inner class. Whenever *//* the text inside the top TextField is changed, a TextEvent is *//* generated and sent to the textValueChanged() method. */ class TextEventHandler implements TextListener { public void textValueChanged(TextEvent event) { TextField tf = (TextField)event.getSource(); tf2.setText("Text is: "+tf.getText()); } } public static void main(String args[]) { TextEventDemo demo = new TextEventDemo(); }}/* This makes sure the application terminates if the window is closed */class WinAdapter extends WindowAdapter{ public void windowClosing(WindowEvent event) { System.exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -