我想知道如果有多个按钮,我们是否可以捕获单击了哪个按钮。
在这个例子中,我们可以使用 joinPoints 达到 //do something1 和 //do something2 部分吗?
public class Test {
public Test() {
JButton j1 = new JButton("button1");
j1.addActionListener(this);
JButton j2 = new JButton("button2");
j2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
//if the button1 clicked
//do something1
//if the button2 clicked
//do something2
}
}