0

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();
}
Michael
  • 169
  • 2
  • 2
  • 9
  • I think you want `presentationController.scrollPane.new velocityCalc()`. (Not sure, because you are ignoring the standard Java convention of uppercase class names and lowercase variable names). – Russell Zahniser Nov 04 '13 at 20:10
  • sorry about the convention thing. Those aren't the actual class names I am using, I replaced them in the question for simplicity sake - my bad! – Michael Nov 04 '13 at 20:15
  • Russell, I just tried your fix and it also worked! Thanks! – Michael Nov 04 '13 at 20:18

0 Answers0