I'm not sure if this helps you but if you are using a action listener I'm guessing you are working with javas swing api. In that case you are maybe extending a class like JFrame or something like that so you could use this: