Java Software Craftsman
Christopher Dodunski wrote:
As we live and program in an object oriented world, I then decided to create a ShipShape class and delegate drawing of each ship to that class by way of forwarding a Graphics2D reference from the JPanel class to the ShipShape class constructor. This, too, was successful.
Java Software Craftsman
Christopher Dodunski wrote:You are suggesting two alternative approaches:
There are three kinds of actuaries: those who can count, and those who can't.
Java Software Craftsman
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Les Morgan wrote:You have elements of animation from using the EDT and Technics commonly used in full screen manually controlled animations. The manual animations characteristically block the events scheduled on the EDT and everything just seemingly stops or become unpredictable at best.
Get rid of your infinite loop processing -- while(true) -- or get rid of your EDT reliance. Use manual or EDT, but rarely have I seen them merged successfully as an early learning exercise.
Brian wrote: "The manual animations characteristically block the events scheduled on the EDT"
• Nowhere in my code is the EDT blocked. If you think otherwise, please tell me what line number(s) you're worried about.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
Brian wrote: "The manual animations characteristically block the events scheduled on the EDT"
• Nowhere in my code is the EDT blocked. If you think otherwise, please tell me what line number(s) you're worried about.
I think Les could have a point here.
If you look at the paintComponent method in the Harbour class, it does
It could well be that one (or more) of the balls Threads is sleeping at that moment. What happens in that case? Does the EDT wait? I have no java at my disposal currently, so I can't check.
Piet Souris wrote:It could well be that one (or more) of the balls Threads is sleeping at that moment. What happens in that case? Does the EDT wait? I have no java at my disposal currently, so I can't check.
Tony Docherty wrote:
What may be a problem though is there is no proper synchronization so the paint method may be painting the ball as the x and y values are being changed. Also shouldn't the 'visible' variable be declared as volatile as it is being used by two different threads.
Tony Docherty wrote:Also shouldn't the 'visible' variable be declared as volatile as it is being used by two different threads.
Brian Cole wrote:
Piet Souris wrote:It could well be that one (or more) of the balls Threads is sleeping at that moment. What happens in that case? Does the EDT wait? I have no java at my disposal currently, so I can't check.
That doesn't make sense. (...)
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:Just tested this at home. The code works without any problem, no matter how hard I tried by resizing the panel as fast as I could. The 'paint' method is not affected in any way by the Thread executing the 'run' method. This is new to me, and if I had a chance to test this earlier, I wouldn't have asked.
Brian Cole wrote:
I still maintain that my code is sound. If the original poster wants each ShipShape object to have its own thread to change its position and heading, then this is the kind of approach he should take. But of course I'm willing to consider further objections.
Or just wrongI did try to "lose" a ball this way several times but failed each time, but I think it's possible if things go just right.
People on both websites need to know about multiple postings, so they don't simply repeat what has already been said elsewhere.Norm Radder wrote:Also posted at: . . .
Java Software Craftsman
Don't get me started about those stupid light bulbs. |