Java编程教程-Java事件处理

改变对象状态被称为事件。例如,点击按钮、拖动鼠标等。java.awt.event 包提供了许多事件类和监听器接口来进行事件处理。

Java事件类和监听器接口

事件类
监听器接口
ActionEvent
ActionListener
MouseEvent
MouseListener and MouseMotionListener
MouseWheelEvent
MouseWheelListener
KeyEvent
KeyListener
ItemEvent
ItemListener
TextEvent
TextListener
AdjustmentEvent
AdjustmentListener
WindowEvent
WindowListener
ComponentEvent
ComponentListener
ContainerEvent
ContainerListener
FocusEvent
FocusListener

执行事件处理的步骤

执行事件处理需要以下步骤:

将组件与监听器注册

注册方法

为了将组件与监听器注册,许多类提供了注册方法。例如:

Button
public void addActionListener(ActionListener a){}
MenuItem
public void addActionListener(ActionListener a){}
TextField
public void addActionListener(ActionListener a){}
public void addTextListener(TextListener a){}
TextArea
public void addTextListener(TextLis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值