import java.awt.*;
import java.awt.event.*;
public class TextFA
{
private Frame f = new Frame("TextArea和TextFiled示例");
private TextField tf = new TextField(20);
private TextArea ta = new TextArea("",5,10,TextArea.SCROLLBARS_BOTH);
public static void main(String[] args)
{
TextFA that = new TextFA();
that.go();
}
void go()
{
f.setLayout(new BorderLayout(0,10));
f.add("North",tf);
f.add("Center",ta);
tf.addActionListener(new TextHandle());
f.addWindowListener(new WindowHandle());
f.setSize(300,400);
f.setResizable(true);
f.setVisible(true);
}
class TextHandle implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
ta.append(tf.getText()+"/n");
tf.setText("");
}
}
class WindowHandle extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}
}
本文介绍了一个简单的Java Swing程序示例,展示了如何使用TextArea和TextField组件创建基本的图形用户界面。用户可以在TextField中输入文本,并通过点击或按下回车键将文本追加到TextArea中。
1380

被折叠的 条评论
为什么被折叠?



