One definite problem in the applet is:
Image img = Toolkit.getDefaultToolkit().getImage("hey.gif");
If you look at the JavaDocs for getImage(String)
it states:
Returns an image which gets pixel data from the specified file, whose format can be either GIF, JPEG or PNG. The underlying toolkit attempts to resolve multiple requests with the same filename to the same returned Image.
The highlight of file was by my choice. Applets and files are rarely used together, and it is not appropriate for this situation. Instead the Image
must be accessed by URL
.
Applet offers instead Applet.getImage(URL)
& getImage(URL,String)
. The 2nd is particularly handy when we need to form an URL
relative to the code base or document base.
If the image is located in the same directory as the HTML, it might be loaded using something along the lines of:
Image img = getImage(getDocumentBase(), "hey.gif");