This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is the problem with this programm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the problem with this programm" Watch "What is the problem with this programm" New topic

What is the problem with this programm

omer omran

Joined: Mar 24, 2004
Posts: 3
Why the applet does not work in the html page .
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ April 27, 2004: Message edited by: Dirk Schreckmann ]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

- Your init() method will never return; it will loop forever creating threads (at least until the VM runs out of memory.)
- init() runs on the Swing event thread, so the screen will never be repainted (since you're blocking the painting thread.) This means that the counter will never be incremented, which means that none of these threads will ever terminate.
- Every thread creates its own Car object, none of which will actually be displayed on the screen (only the original one will be) so all those repaint() calls won't do anything anyway!
To get you on the right track: rename your "init()" method to "start()", and get rid of that "while" loop; then in "run", get rid of the variable "c" altogether. Don't create any Car object, and refer to the member variable "i" implicitly.
Note that since you haven't overridden stop() to do anything, calling it will have no effect. What you want to do is break out of that while loop, not call stop().

[Jess in Action][AskingGoodQuestions]
omer omran

Joined: Mar 24, 2004
Posts: 3
Thanks :
But the while loop int the init() methode to make multible moving rectangle at random, not single rectangle .
how can I make that .
I agree. Here's the link:
subject: What is the problem with this programm
jQuery in Action, 3rd edition