textexample.java

来自「清华大学辛运帏java程序设计第二版源代码」· Java 代码 · 共 42 行

JAVA
42
字号
import java.awt.*;
import java.awt.event.*;

public class TextExample
	implements ActionListener,TextListener {
	Frame f;
	TextField tf1;
	TextArea ta1,ta2;

	static public void main(String args[]) {
		TextExample te = new TextExample();
		te.go();
	}

	public void go() {
		f = new Frame("Text Example");
		f.setLayout( new FlowLayout() );

		tf1 = new TextField("Init",20);
		tf1.addActionListener(this);
		tf1.addTextListener(this);

		ta1 = new TextArea("Initial text",4,30);
		ta1.addTextListener(this);
		ta2 = new TextArea("Only horizontal scrollbar ",4,30,
		TextArea.SCROLLBARS_HORIZONTAL_ONLY);

		f.add(tf1);
		f.add(ta1);
		f.add(ta2);
		f.setSize(300,300);
		f.setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		ta2.append("\nActionPerformed");
	}

	public void textValueChanged(TextEvent e) {
		ta2.append("\nTextValueChanged");
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?