Saturday, December 19, 2009

Section 15.3. Using Network Resources from an Applet











[Page 714]

15.3. Using Network Resources from an Applet


Suppose you want to write an applet that will automatically display a slide show consisting of images or documents that you have prepared and stored on your Web site. Perhaps you can use such an applet to give people who visit your site a tour of your campus (Fig. 15.8). Or perhaps a company might use such an applet to advertise its products. In addition to making the slide show available through its main Web site, you can imagine it running continuously on a computer kiosk in the company's lobby.




Figure 15.8. An applet that continuously displays slides downloaded from the Web.








Problem statement





Specifying Web resources




In order to solve this problem we have to be able to download and display Web resources. As you know, Web resources are multimedia. That is, they could be documents, images, sounds, video clips, and so on. All Web resources are specified in terms of their Uniform Resource Locators (URLs). Thus, to download an image (or an HTML file or audio clip), we usually type its URL into a Web browser. We want our program to know beforehand the URLs of the images it will display so that there will be no need to input the URL. We want to implement something like the following algorithm:


[Page 715]

repeat forever
Generate the URL for the next slide.
Use the URL to download the image or document.
Display the image or document.


A URL specification is just a String, such as


http://starbase.trincoll.edu:80/~jjjava/slideshow/slide1.gif


which describes how to retrieve the resource. First it specifies the protocol or method that should be used to download the resource (http). Then it provides the domain name of the server that runs the protocol and the port number where the service is running (starbase.trincoll.edu:80). Next the URL specifies the resource's file name (jjjava/slideshow/slide1.gif).












No comments: