18.10. Chapter Summary

 
[Page 564 ( continued )]

Chapter Summary

  • The Web browser controls and executes applets through the init , start , stop , and destroy methods in the Applet class. Applets always extend the Applet class and implement these methods, if applicable , so that they can be run by a Web browser.


    [Page 565]
  • JApplet is a subclass of Applet . It should be used for developing Java applets with Swing components .

  • The applet bytecode must be specified, using the <applet> tag in an HTML file to tell the Web browser where to find the applet. The applet can accept string parameters from HTML using the <param> tag.

  • When an applet is loaded, the Web browser creates an instance of the applet by invoking its no-arg constructor. The init method is invoked after the applet is created. The start method is invoked after the init method. It is also called whenever the applet becomes active again after the page containing the applet is revisited. The stop method is invoked when the applet becomes inactive.

  • The destroy method is invoked when the browser exits normally to inform the applet that it is no longer needed and should release any resources it has allocated. The stop method is always called before the destroy method.

  • The procedures for writing applications and writing applets are very similar. An applet can easily be converted into an application, and vice versa. Moreover, an applet can be written with the additional capability of running as an application.

  • You can pass arguments to an applet using the param attribute in the applet's tag in HTML. To retrieve the value of the parameter, invoke the getParameter(paramName) method.

  • The Applet 's getParameter method can be invoked only after an instance of the applet is created. Therefore, this method cannot be invoked in the constructor of the applet class. You should invoke this method from the init method.

  • You learned how to incorporate images and audio in Java applications and applets. To load audio and images for Java applications and applets, you have to create a URL for the audio and image. You can create a URL from a file under the class directory or from an Internet source.

  • To play an audio, create an audio clip from the URL for the audio source. You can use the AudioClip 's play() method to play it once, the loop() method to play it repeatedly, and the stop() method to stop it.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net