事件驱动程序设计

一、动作事件(ActionEvent)

ActionListener

public void actionPerformed(ActionEvent e)

二、窗口事件(WindowEvent)

WindowListener

Window类的任何一个子类都可能触发下面的窗口事件:

打开窗口、正在关闭窗口、关闭窗口、激活窗口、变成非活动窗口、最小化窗口和还原窗口
(windowOpened,windowClosing,windowClosed,windowActivated,windowDeactivated,windowIconified,windowDeiconified)。

三、鼠标事件(MouseEvent)

当在一个组件上按下、释放、点击、移动或拖动鼠标时就会产生鼠标事件。

MouseEvent类继承InputEvent类,所以可以在MouseEvent对象上使用InputEvent类中定义的方法。

Java提供了两个处理鼠标事件的监听器接口MouseListener和MouseMotionListener。

实现MouseListener接口可以监听如鼠标的按下、释放、输入、退出或点击的动作,然后实现MouseMotionListener
接口以监听如拖动鼠标或移动鼠标的动作。 mouseDraggedmouseMoved

四、按键事件(KeyEvent)

KeyListener

按下、释放或敲击一个键。

KeyPressed、KeyReleased、KeyTyped处理器来处理KeyEvent。

getKeyCode()返回常量值(VK_UP、VK_DOWN等等)、getkeyChar()返回输入的字符。

五、Timer能够触发actionEvent

Timer(delay:int,listener:actionListener);创建一个带特定的毫秒延时和ActionListener的Timer对象。

addActionListener();

start();

end();

setDelay(delay:int)

原文地址:https://www.cnblogs.com/mydesky2012/p/4543560.html