I want to track specific components clicked in a specific order.
I am using getSource and flags like this:
public void actionPerformed(ActionEvent e) {
JButton q = (JButton)e.getSource();
JRadioButton w = (JRadioButton)e.getSource();
if (q.equals(mybutton)) {
if (flag == false) {
System.out.print("test");
flag = true;
}
}
This works perfectly for JButtons, the problem is using it for JRadioButtons as well. If I use getSource on them both, click a button and it will result in an cast exception error since the button can't be cast to a Radiobutton.
How can I work around this problem?