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.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("You clicked the button, using an ActionListener");
}
});
or
JButton but = new JButton();
but.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("You clicked the button, using a MouseListenr");
}
});