获取被点击按钮的文本,我只会以下面方式实现
JButton button = new JButton("按钮");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
String text = button.getText(); // 按钮
}
});
但既然Listener是绑定到button上的,能否直接在actionPerformed中直接获取button呢?
慕田峪7331174
相关分类