1.当事件发生后,系统会通知我们去处理这些事件,对这些事件做出相应的处理的程序,称为事件处理器
2.通常用到的事件类在java.awt.event包中
3.事件监听器是在一个事件发生时被通知的对象,也称为事件处理器,也分为很多种,以接口形式
4.事件源提供了一组方法,用于为事件注册一个或多个监听器对象,并向其发送事件对象
5.每种不同的事件都有自己的注册方法,一般形式为:
public void add Listener(TypeLietener e)添加
public void remove Listener(TypeLietener e)移除
6.写一个内部类
public class Login exdents JFrame{
private Jlabel lname;
private Jlabel lpass;
private JTextField tname;
private JPasswordField tpass;
private Jlabel login;
private void initEvent(){
login.addActionListener(new MyListener());
}
private void init(){
lname=new Jlabel(“用户名”);
lpass=new Jlabel(“密码”);
tname=new JTextField(14);
tpass=new JPasswordFieldField(14);
login=new JButton(“登录”);
this.setLayout(new FlowLayout(FlowLayout.center));
this.add(lname);
this.add(tname);
this.add(lpass);
this.add(tpass);
this,add(login);
Dimension dim=getToolkit().getScreenSize();
this.setRestzablr(false);
this.setTitle(“QQ登录”);
this.setSize(260,125);
this.setLocation(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}
public Login(){
init();}
}
public class Test{
publuc static void main(String[] args){
new login()}
Class MyListener implements ActionListener{
public void actionPerformed(ActionEvent e) System.out.println(“单击了按钮”+tnme.getText()+","+tpass.getText()+","+e.getSourse());}
}
}
7.package com.imau.gui;
import java.awt.;
import javax.swing.;
import java.awt.event.*;
public class EventDemo extend JFrame{
<