Is there a way for me to pass variables into an actionlistener without calling them as final? I’d like to use these two points inside some sort of timed way… I tried Thread.sleep() but for some reason it doesn’t mesh well with the rest of the program. This is the format I’d really like to use, but I’m aware it might be impossible to make it work.
I’m open to any and all advice. Thanks!
(I’m sorry if this is a stupid question, I’ve looked for an answer but just can’t seem to find one.)
public void timedMain(Point current, Point wanted){
ActionListener taskPerformer = new ActionListener(){
public void actionPerformed(ActionEvent evt){
System.out.println(wanted+" "+current);}};
actiontimer = new Timer(delay, taskPerformer);
actiontimer.start();}
You could do this, which avoids declaring the parameters as final.
Or you could change the types of
currentandwantedso that they were mutablePointholders, and have theactionPerformedmethod look at the current values in the holders.But there is no way to declare the inner class so that it can see changes made to a variable in an enclosing method scope … if that is what you are trying to do.