TextExample

来源:互联网 发布:超级奇门遁甲排盘软件 编辑:程序博客网 时间:2024/06/06 08:30

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,20);

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

  }