Java Reference
In-Depth Information
Fig. 12.13 Output from applet ImageTest2b under IE9
The size of the image is automatically scaled to fit these dimensions. For
example:
g.drawImage(image,100,100,200,150,this);
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:
g.drawImage (
image,50,60,getWidth()-100,getHeight()-120,this);
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 .
12.6
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
Search WWH ::




Custom Search