You are creating an anonymous instance of ActionListener
and attempting to access the MyButton
to which you adding the listener via this
– but this
is the ActionListener
. You should be able to use the source of the ActionEvent
but you’ll need to cast it.
JComponent source = (JComponent)ae.getSource();
menu.show(source, source.getWidth()/2, source.getHeight()/2);
CLICK HERE to find out more related problems solutions.