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.

670 Chapter 17 GUI Components<br />

**17.19 (Display country flag and flag description) Listing 17.4, ComboBoxDemo.java,<br />

gives a program that lets users view a country’s flag image and description<br />

by selecting the country from a <strong>com</strong>bo box. The description is a string coded<br />

in the program. Rewrite the program <strong>to</strong> read the text description from a file.<br />

Suppose that the descriptions are s<strong>to</strong>red in the files description0.txt, . . ., and<br />

description8.txt under the text direc<strong>to</strong>ry for the nine countries Canada, China,<br />

Denmark, France, Germany, India, Norway, the United Kingdom, and the<br />

United States, in this order.<br />

**17.20 (Slide show) <strong>Programming</strong> Exercise 16.13 developed a slide show using images.<br />

Rewrite that program <strong>to</strong> develop a slide show using text files. Suppose ten<br />

text files named slide0.txt, slide1.txt, . . ., and slide9.txt are s<strong>to</strong>red in the text<br />

direc<strong>to</strong>ry. Each slide displays the text from one file. Each slide is shown for one<br />

second, and the slides are displayed in order. When the last slide finishes, the<br />

first slide is redisplayed, and so on. Use a text area <strong>to</strong> display the slide.<br />

**17.21 (Retrieve files from Web) Write a <strong>Java</strong> program that retrieves a file from a Web<br />

server, as shown in Figure 17.32. The user interface includes a text field in<br />

which <strong>to</strong> enter the URL of the file name, a text area in which <strong>to</strong> show the file,<br />

and a but<strong>to</strong>n that can be used <strong>to</strong> submit an action. A label is added at the bot<strong>to</strong>m<br />

of the applet <strong>to</strong> indicate the status, such as File loaded successfully or Network<br />

connection problem.<br />

FIGURE 17.32<br />

The program displays the contents of a specified file on the Internet.

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

Saved successfully!

Ooh no, something went wrong!