public class Square extends JButton {   
    ... 
}

What's the best way for a JButton to handle a MouseClick that changes the background color of itself? Do I want to add/overwrite an ActionListener/MouseListener/etc?

有帮助吗?

解决方案

Yes, you will need to add an ActionListener and do your mumbo-jumbo in actionPerformed(). Use the setBackground() to change the background color. :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top