组件TextArea示例

来源:互联网 发布:淘宝西瓜家衣服怎么样 编辑:程序博客网 时间:2024/05/23 01:58

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);
 }
}
}