However, when I call timer.start() inside the mouseReleased(...) method, it doesn't work, and "10 seconds has passed" is never outputted to the screen.
you must have another 'timer' object, otherwise the compiler would give you a 'cannot resolve symbol' error at timer.stop() ('timer' is declared after)
try changing javax.swing.Timer timer=new javax.swing.Timer(1000,taskPerformer); to timer=new javax.swing.Timer(1000,taskPerformer);
do you have both of these in your constructor? javax.swing.Timer timer=new javax.swing.Timer(1000,taskPerformer); and timer=new Timer(3000,taskPerformer);
no, outside the constructor is javax.swing.Timer timer;
then inside is timer=...
My code is 3000 lines long, and the GUI part is confusing too. But basically when I call timer.start() after pressing the start button on the menu... the classes' actionPerformed method calls a method which uses timer.start(), and that works fine.
But when the mouse is realised and its the computers turn to move, the timer doesnt work again. I could post the whole code if you want to look at it, or just perhaps the gui, but then you wouldn't be able to execute it.
Thanks, I ran your program but minus the javax.swing.timer part at the bottom, and it works fine, but thats essentially what mine is. And mine works like that.
But I need to restart the timer after the mouse has been released, The button press (start button) is just to start the chess game, and when you release a piece over a square... this should invoke the timer to start while the computer thinks about his move... but whats happening is that the computer keeps thinking forever.
Its only when we start the game with computer having first go, and when we click the start button that timer.start() works.
Perhaps if you could implement the MouseListener interface, so that mouseReleased(MouseEvent e) triggers timer.start(), as well as triggering it from the start button. I can't seem to do it, I'll try it with your code though, and if you could try to, that would be great.
OK, so I've amended your code, and it works now. Why doesn't my code work
Here is what I did to yours
I'll just have to take another look at my code, it should essentially be the same as this. Thanks for your help [ May 11, 2006: Message edited by: colin shuker ]
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, that will fit in a stocking