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.
Typically, the
init()method initializes the components/layout of the applet. The actual drawing is done bypaint().You can override the
paint()method by callingsuper.paint(..)and adding your own code to it:The delay you are noticing is because the
Runnableyou pass toSwingUtilities.invokeLater()is invoked somewhere betweeninit()andpaint()