我有兴趣获得由另一个类的多个组件生成的 ActionEvent ......请帮忙。下面给出示例。
class MyFrame {
public MyFrame() {
JFrame window = new JFrame();
Container c = window.getContentPane();
c.setLayout(new BorderLayout());
JButton btn1 = new JButton("Save");
JButton btn2 = new JButton("Delete");
c.add(btn1);
c.add(btn2);
EventHandler handler = new EventHandler();
btn1.addActionListener(handler);
btn2.addActionListener(handler);
.................
}
}
class EventHandler implements ActionListener {
public void actionPerformed(ActionEvent ae)
{
// what can i do here to get Event and also recognized which component fired event?
// I have used getSource(). but problem is not solved.
if ( ae.getSource() == btnSave)
{
}
}
}
请尽快帮助我...