19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The presentNation(index) method (lines 63–68) presents a nation with the specified<br />

index. It sets a new image in the label (line 64), synchronizes with the <strong>com</strong>bo box by setting<br />

the selected index (line 65), and plays the new audio (line 67).<br />

The applet’s start and s<strong>to</strong>p methods are overridden <strong>to</strong> resume and suspend the audio<br />

(lines 70–78).<br />

Chapter Summary 697<br />

18.27 Which code sets the initial image icon? Which code plays the initial audio clip?<br />

18.28 What does the program do when the Suspend but<strong>to</strong>n is clicked? What does the program<br />

do when the Resume but<strong>to</strong>n is clicked?<br />

✓Point✓ Check<br />

KEY TERMS<br />

applet 673<br />

applet container 677<br />

archive 674<br />

HTML 673<br />

signed applet 676<br />

tag 673<br />

CHAPTER SUMMARY<br />

1. JApplet is a subclass of Applet. It is used for developing <strong>Java</strong> applets with Swing<br />

<strong>com</strong>ponents.<br />

2. The applet class file must be specified, using the tag in an HTML file <strong>to</strong><br />

tell the Web browser where <strong>to</strong> find the applet. The applet can accept string parameters<br />

from HTML using the tag.<br />

3. The applet container controls and executes applets through the init, start, s<strong>to</strong>p,<br />

and destroy methods in the Applet class.<br />

4. When an applet is loaded, the applet container creates an instance of it by invoking its<br />

no-arg construc<strong>to</strong>r. The init method is invoked after the applet is created. The<br />

start method is invoked after the init method. It is also called whenever the applet<br />

be<strong>com</strong>es active again after the page containing the applet is revisited. The s<strong>to</strong>p<br />

method is invoked when the applet be<strong>com</strong>es inactive.<br />

5. The destroy method is invoked when the browser exits normally <strong>to</strong> inform the applet<br />

that it is no longer needed and should release any resources it has allocated. The s<strong>to</strong>p<br />

method is always called before the destroy method.<br />

6. Applications and applets are very similar. An applet can easily be converted in<strong>to</strong> an<br />

application, and vice versa. Moreover, an applet can be written with a main method <strong>to</strong><br />

run standalone.<br />

7. You can pass arguments <strong>to</strong> an applet using the param attribute in the applet’s tag in<br />

HTML. To retrieve the value of the parameter, invoke the getParameter(paramName)<br />

method.<br />

8. The Applet’s getParameter method can be invoked only after an instance of the<br />

applet is created. Therefore, this method cannot be invoked in the construc<strong>to</strong>r of the<br />

applet class. You should invoke this method from the init method.<br />

9. You learned how <strong>to</strong> incorporate images and audio in <strong>Java</strong> applications and applets. To<br />

load audio and images for <strong>Java</strong> applications and applets, you have <strong>to</strong> create a URL object<br />

for the audio and image file. The resource files must be s<strong>to</strong>red in the class direc<strong>to</strong>ry.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!