Java anonymous class that implements ActionListener?
问题 I was recently doing a programming assignment that required us to implement in code a program specified by a UML diagram. At one point, the diagram specified that I had to create an anonymous JButton that displayed a count (starting at one) and decremented each time it was clicked. The JButton and its ActionListener both had to be anonymous. I came up with the following solution: public static void main(String[] args) { JFrame f = new JFrame("frame"); f.setDefaultCloseOperation(JFrame.EXIT_ON