addMouseListener or addActionListener or JButton?

前端 未结 4 837
小蘑菇
小蘑菇 2021-01-18 14:24

When defining the behaviour of a simple click on a JButton, which is the right way to do it? And, what\'s the difference?

JButton but = new JButton();
but.ad         


        
4条回答
  •  盖世英雄少女心
    2021-01-18 14:47

    If you want to do something when a Jbutton is clicked, action listener is better because mouse listener does not recognize that a mouse is clicked on a button if a user presses the mouse on a JButton and then moves the mouse a little bit before releasing the mouse button while remaining within the button the whole time, but action listener does. MouseListener requires that mouse clicks have no movement between mouse press and mouse release, which is not the case for my users.

提交回复
热议问题