I want to run this code without Timer
. I deleted Timer
variables and function, but the code doesn't work, and I have just image without change. How can i run this code without timer. I need that just for one time run.
Asked
Active
Viewed 65 times
-3
-
2How do you expect image change to occur if you delete all code that changes it? Your question is baffling. – Hovercraft Full Of Eels Oct 10 '14 at 12:09
-
Maybe you just want to implement a stopping condition in the `actionPerformed`. Or set `timer.setRepeats(false);`. Not really sure what you mean by "only run once". Maybe you should elaborate – Paul Samsotha Oct 10 '14 at 12:09
-
The question is very easy , RUN code without Timer ! – Sani Ya Oct 10 '14 at 12:13
-
2That's not a question, that's an order. – Alexander_Winter Oct 10 '14 at 12:15
-
ok , i try run the code without timer , but after delete the timer code dosent work , how can i run code just one time – Sani Ya Oct 10 '14 at 12:17
-
You could just call `Collections.shuffle(list)` before adding the `JPanel`s to the `JFrame`. – Lone nebula Oct 10 '14 at 12:18
-
1@trashgod for some reason I had a feeling the OP didn't write this code – Paul Samsotha Oct 10 '14 at 12:59
1 Answers
0
Simple solution: Instead of instantiating a timer and calling timer.start(), feel free to call actionPerformed(ActionEvent e) method directly from the constructor.
The Hard Way: Your code contains a lot of mistakes. Calling actionPerformed directly from your constructor is nonsense, since there is no action event to react. Try to begin with moving the code from actionPerformed() method into createPane() method. At least.
Next issue with your code is possible drawing even before the object is constructed. You should at least make method createPane() public and call it from public static void main(String[] args) method after instantiating the ImageLabelPanel.
-
It's my [code](http://stackoverflow.com/a/3078354/230513), but I'm always interested in learning from mistakes. – trashgod Oct 10 '14 at 13:03