This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "inconsistent behaviour" Watch "inconsistent behaviour" New topic
Author

inconsistent behaviour

Frantizek K
Greenhorn

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
Sheriff

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

As far as I know, you do not need to call
theApplet.init();
nor
theApplet.start();
explicitly.

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 http://www.javaranch.com/name.jsp for more details).


JavaBeginnersFaq
"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: 15950
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: inconsistent behaviour
 
Similar Threads
Event Handling Question
Help with Errors
Help With Repaint Method
Help with graphics
Transparent frame using Robot class and its createScreenCapture() method - help pls!