《Java核心技术 卷I》用户界面AWT事件继承层次

AWT事件继承层次

EventObject类有一个子类AWTEvent,它是所有AWT事件类的父类。

Swing组件会生成更多其他事件对象,都直接拓展自EventObject而不是AWTEvent。

AWT将事件分为底层(low-level)事件和语义事件。

语义事件:表示用户的动作事件,例如点击按钮,调节滚动条。

底层事件:使得语义事件得以发生的事件,例如按下鼠标,移动鼠标等。

AWT事件类的继承关系图

java.awt.event包中最常用的语义事件类:

  • ActionEvent(对应按钮点击,菜单选择,选择列表,文本域中按回车)
  • AdjustmentEvent(用户调用滚动条)
  • ItemEvent(用户从复选框或列表框中选择一项)

最常用的5个底层事件类是:

  • KeyEvent(一个键按下或释放)
  • MouseEvent(鼠标键按下、释放、移动、拖动)
  • MouseWheelEvent(鼠标滚轮转动)
  • FocusEvent(某个组件获得焦点或失去焦点)
  • WindowEvent(窗口状态改变)

最重要的AWT监听器接口、事件和事件源

接口

方法

参数/访问方法

事件源

ActionListener

actionPerformed

ActionEvent

  • getActionCommand
  • getModifiers

AbstractButton

JComboBox

JTextField

Timer

AdjustmentListener

adjustmentValueChanged

AdjustmentEvent

  • getAdjustable
  • getAdjustmentType
  • getValue

JScrollbar

ItemListener

itemStateChanged

ItemEvent

  • getItem
  • getItemSelectable
  • getStateChange

AbstractButton

JComboxBox

FocusListener

focusGained

focusLost

FocusEvent

  • isTemporary

Component

KeyListener

keyPressed

keyReleased

keyTyped

KeyEvent

  • getKeyChar
  • getKeyCode
  • getKeyModifiersText
  • getKeyText
  • isActionKey

Component

MouseListener

mousePressed

mouseReleased

mouseEntered

mouseExited

mouseClicked

MouseEvent

  • getClickCount
  • getX
  • getY
  • getPoint
  • translatePoint

Component

MouseMotionListener

mouseDragged

mouseMoved

MouseEvent

Component

MouseWheelListener

mouseWheelMoved

MouseWheelEvent

  • getWheelRotation
  • getScrollAmount

Component

WindowListener

windowClosing

windowOpened

windowIconfied

windowDeiconified

windowClosed

windowActivated

windowDeactivated

WindowEvent

  • getWindow

Window

WindowFocusListener

windowGainedFocus

windowLostFocus

WindowEvent

  • getOppositeWindow

Window

WindowStateListener

windowStateChanged

WindowEvent

  • getOldState
  • getNewState

Window

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿立聊全栈

有作用的,有闲钱的支持一点。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值