Reputation: 1193
What is the correct way to be notified once a Swing applet has finished its drawing? I'm writing some timing code to measure how long the applet takes and want to include the time to display any graphics.
At the end of my init() method which performs all the drawing, I passed in a Runnable to SwingUtilities.invokeLater that slept for 10 seconds. I saw the delay prior to the graphics being displayed. I would have thought that the delay would occur after the graphics since I had understood it would be queued up after the drawing calls. I tried moving this sleep test code to start() and got the same results.
Based on my testing with a javascript alert message, it appears that an onload event placed on a HTML body tag is also triggered prior to the graphics being drawn.
Upvotes: 0
Views: 296
Reputation: 8490
Typically, the init()
method initializes the components/layout of the applet. The actual drawing is done by paint()
.
You can override the paint()
method by calling super.paint(..)
and adding your own code to it:
public void paint(Graphics g) {
super.paint(g);
// Add your code
}
The delay you are noticing is because the Runnable
you pass to SwingUtilities.invokeLater()
is invoked somewhere between init()
and paint()
Upvotes: 4