/*ch0707.java*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ch0707 extends JFrame implements ActionListener
{ JLabel lb=new JLabel("组件和事件处理：");
  JButton bt=new JButton("OK");
  JTextField tf=new JTextField(20);
  JTextArea ta=new JTextArea(10,20);
  public ch0707()
  { super("组件综合实例");
    Container c=getContentPane();
    c.setLayout(new FlowLayout());     //指定布局方式为顺序布局
    c.add(lb);                         //将组件添加到容器中
    c.add(ta); 
    c.add(bt);
    c.add(tf);
    bt.addActionListener(this);
    tf.addActionListener(this);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(200,100);
    setVisible(true);
  }

  public void actionPerformed(ActionEvent e)
  { if(e.getSource()==bt)
      ta.append("现在按下按钮引发的事件"+"\n");
    else
    { 
      ta.append(tf.getText()+"\n");
      ta.append("现在因在文本框里回车而引发的事件"+"\n");
    }
  }

  public static void main(String args[])
  { new ch0707();
  }
}
