Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

java - Pros and cons of using ActionListener vs. MouseListener for capturing clicks on a JButton

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

An ActionListener is used to handle the logical click of a button. A click happens

  • 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

A MouseListener only handles low-level mouse events.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...