I have a class called Game and a button in it with the following code
public Game(){
(some code..)
btn_start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
(some code..)
timer_task = new MyTask();
(some code..)
}
});
}
}
My problem is that MyTask requires an object of type “Game” (for various reason).
How can i send to MyTask() the class that my actionListener method is in?
Is there such a thing in Java?
I tried using .this but it says that it refers to the ActionListener.
Try using
Game.thisinsteadThis basically tells Java to use the outter class reference of
thisinstead