First of all, I'm sorry if this is the wrong forum to post my problem. I wasn't sure if it would fit better in the threads forum or here or the beginner's ..
I have this task of animating 2 strings and one image in an Applet.
Basically what the 2 strings would do is move from left to the right of the screen and the image will move from right to left, all at the same time.
My question is, do I use 3 threads in my applet so those 2 strings and the image will move accordingly all at the same time?
Yes, that's perfectly possible. Each animated object can have its own thread. If the strings move in tandem, then one thread for both of them may suffice, but there's nothing wrong with creating multiple threads.
Thanks! So I got started on this.. This is what I have so far:
I can't get it to work using that way.. Any ideas why? It doesn't move at all.. Also, I'm not sure how to have 2 threads going on the same time. I'm planning to create 1 more class..
Also, is it possible to have a paint method that does something different from another paint method?
Why is Move extending Test2Threads? That's not the way to go. Here's a Move class that'll work. I'll leave it to you to figure which changes you need to make to the main class to use it:
Hi, I worked on it again tonight and this is what I have:
I'm curious about the music thread though.. Is it okay if it's like that or should a separate thread be created for it? I'm thinking that I have too many classes for a small task like this ..
Also, I would like to know if the code has good OO design? Thanks!
I wouldn't use separate classes Move and Move2. They only differ in the way the for-loop is set up. That could be controlled be a boolean parameter ("up" or "down") that is passed into the constructor.
I wouldn't use the thread name, but yes, you'd need some differentiating logic. All data that's relevant for that logic should be passed in through the constructor or through setter methods.
Hi Ulf, I really tried to think of some differentiating logic but I just can't figure out how the run method will know which for loop to run .. If I'm not mistaken, you were trying to tell me to do something like this where there are two threads but only one job (run method).