Inside my actionPerformed
method I have the two following lines of code,
JButton pressed =(JButton)e.getSource();
JMenuItem pressedSave = (JMenuItem)e.getSource();
Why is this not allowed? I get the following compiler error
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton cannot be cast to javax.swing.JMenuItem
I need to be able to get the text for both a JButton
and a JMenuItem
. How can I do this?