Forums Register Login

animation in applet

+Pie Number of slices to send: Send
Hi,

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?

Thanks!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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:
+Pie Number of slices to send: Send
Thanks Ulf! Works great!



+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I have additional codes inside the for loop of Move2

Something like:



Where I switch images. Do you think I should still combine though?
+Pie Number of slices to send: Send
Sounds still like something that can be handled by parameters.
+Pie Number of slices to send: Send
Does it make sense if I do a setName() on those two threads then do something like:




Is that what you meant?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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).



Any clues? I really appreciate your help.
+Pie Number of slices to send: Send
 

you were trying to tell me to do something like this where there are two threads but only one job (run method).


Almost :-) What I meant was to use just one class; but you will need two separate objects. So it would be something like:

and the Move constructor would be

public Move (Test2Threads parent, int appWidth, boolean leftToRight)


Then you just need to think about how to use the "leftToRight" parameter for controlling the loop.
+Pie Number of slices to send: Send
Ah, you're a genius Ulf, thanks a lot!

I never thought of actually creating two move objects .. I kept on thinking how to identify which thread is going to call the run() method
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1366 times.
Similar Threads
Issues with Jar Files and loading images
Thread to create and load large list of images
special effects for cardlayout of pictures?
creatign multiple threads
saving graphics
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:40:10.