事件监听器2(代码示例,来自FSM )
使用闭包前:
public void init() { JButton button = ...; button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { handleAction(ev); } }); } public void handleAction(ActionEvent ev) { // handle event } |
public void init() { JButton button = ...; button.addActionListener(this#handleAction(ActionEvent)); } public void handleAction(ActionEvent ev) { // handle event } |