addMouseListener or addActionListener or JButton?

前端 未结 4 834
小蘑菇
小蘑菇 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:38

    You should be able to press that button using keyboard also. So, if you add just the mouse listener you will not get the 'press' event if using keyboard.

    I would go for the action listener, it's more clear.

提交回复
热议问题