The primary chunk of my code is presentationController
(extends JFrame). Within that, I create an object of type
scrollPane = projectsScrollPane();
(extends JScrollPane).
I also create an object of type presentation
.
The object scrollPane
has
Timer timer = new Timer();
TimerTask task = new velocityCalc();
where velocityCalc is written as
public class velocityCalc extends TimerTask {... do stuff ...}
Within the presentation
object, I cancel said timer, and later would like to renew it, but am unable to do so.
Canceling looks like:
presentationController.scrollPane.task.cancel;
which works as expected. Creating a new task looks like:
presentationController.scrollPane.task = new presentationController.scrollPane.velocityCalc();
presentationController.scrollPane.timer.scheduleAtFixedRate(presentationController.scrollPane.task, 0, 30);
but the portion after the equals sign in the first line is underlined in red (error), and asks me to
"Create class 'velocityCalc' in package 'presentationController.scrollPane'"
The two lines of code are within a mouseListener (mouseReleased).
This code was working perfectly before, but that was when all the code was contained within presentationController
. I have since then moved the Timer
and TimerTask
to projectScrollPane
and the controlling lines of code to presentation
, as described above.
Any thoughts? Hopefully this has been clear enough!
Thanks in advance!
EDIT - SOLUTION:
I created a method within projectsScrollPane
that renews the task
and now it works fine. Probably how I should have done it in the first place, rather than having everything public.
public void createTimer(){
task = new velocityCalc();
}