Fig. 12.13 Output from applet ImageTest2b under IE9
The size of the image is automatically scaled to fit these dimensions. For
By using methods getWidth and getHeight of class Component , the image may
also be drawn relative to the size of the applet, which can enhance the layout of the
Web page signifi cantly. For example:
In the above example, the image will be scaled to fi t within an area that is 50
pixels in from left and right sides of the applet window and 60 pixels in from the top
and bottom of the window. ImageIcon s have no direct scaling mechanism. However,
ImageIcon has a getImage method that returns an Image reference which can then
be used as above by drawImage .
Using Sound in Applets
As noted in the previous chapter, the standard Java classes provide two methods for
the playing of audio clips:
method play of class Applet ;
method play of the AudioClip interface.
Since we were concerned solely with applications (as opposed to applets) in the