使用ActionListener与MouseListener捕获JButton点击的优缺点 [英] Pros and cons of using ActionListener vs. MouseListener for capturing clicks on a JButton
本文介绍了使用ActionListener与MouseListener捕获JButton点击的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JButton,并希望捕获鼠标点击它。使用ActionListener与在JButton上使用MouseListener之间有什么实际和哲学上的区别?
I have a JButton, and would like to capture mouse clicks on it. What are the practical and philosophical differences between using an ActionListener vs. using a MouseListener on the JButton ?
推荐答案
ActionListener用于处理按钮的逻辑单击。点击发生
An ActionListener is used to handle the logical click of a button. A click happens
- 当按下鼠标然后在按钮上释放时,
- 或当使用该按钮的键盘快捷键,
- 或当按钮具有焦点并按下空格键时,
- 或当按钮是默认按钮和Enter按下,
- 或以编程方式调用按钮的click()方法
- when the mouse is pressed then released on a button,
- or when the keyboard shortcut of that button is used,
- or when the button has the focus and the space bar is pressed,
- or when the button is the default button and Enter is pressed,
- or when the button's click() method is called programmatically
MouseListener只处理低级鼠标事件。
A MouseListener only handles low-level mouse events.
这篇关于使用ActionListener与MouseListener捕获JButton点击的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文