File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes inconsistent behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "inconsistent behaviour" Watch "inconsistent behaviour" New topic

inconsistent behaviour

Frantizek K

Joined: Jun 14, 2000
Posts: 2
I am confused about the results produced by the following program.

The program initializes the screen ( by calling drwinit()) and then draws on the screen (over the initialization). The Thread kicker is used in animation of the screen. The boolean initflag is a boolean flag for the initialization of the screen.
The program, run as an application, works fine.
As an applet it works fine only once out of 10 times.
90% of time, the applet (run in appletviewer) initializes the
image on the screen ( the method drawinit() ), then ERASES the screen and draw on the empty screen. The other 10% of the time, the screen is not erased after the initialization.
My questions are:
1. Why the program exhibits this inconsistent behaviour when run as an applet?
2. How can I change it such that it will not erase the screen
after the mathod drawinit()?

[This message has been edited by Marilyn deQueiroz (edited September 06, 2001).]
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
I added code tags to help make your code more readable.

As far as I know, you do not need to call

Typically you override start() to start or resume threads.
From the code you have provided, it seems that the screen should not be erased, but I don't see where you call the update() method.

Also, I would request that you re-register following the JavaRanch guidelines (See for more details).

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

It's highly questionable to make the paint() operation conditional. paint() gets called for a LOT of reasons. Any time that the GUI has reason to suspect that the client area has been corrupted - not just when data has changed.
A lot of windowing systems can avoid calling paint() for simple operations like moving someone else's window over yours because they cache your image as a bitmap, but sooner or later, paint() WILL get called. Don't depend on the windowing system.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: inconsistent behaviour
It's not a secret anymore!