29.9. JFileChooser

 
[Page 857 ( continued )]

Programming Exercises

Sections 25.2

25.1* ( Loan server ) Write a server for a client. The client sends loan information (annual interest rate, number of years , and loan amount) to the server (see Figure 25.23(b)). The server computes monthly payment and total payment and sends them back to the client (see Figure 25.23(a)). Name the client Exercise25_1Client and the server Exercise25_1Server.
Figure 25.23. The client in (b) sends the annual interest rate, number of years, and loan amount to the server and receives the monthly payment and total payment from the server in (a).


[Page 858]
25.2 ( Network I/O using Scanner and PrintWriter ) Rewrite the client and server programs in Listings 25.1 and 25.2 using a Scanner for input and a PrintWriter for output. Name the client Exercise25_2Client and the server Exercise25_2Server.

Sections 25.3 “25.4

25.3* ( Loan server for multiple clients ) Revise Exercise 25.1 to write a server for multiple clients.

Section 25.5

25.4 ( Web visit count ) The example in §25.5, "Applet Clients," created an applet that shows the number of visits made to a Web page. The count is stored in a file on the server side. Every time the page is visited or reloaded, the applet sends a request to the server, and the server increases the count and sends it to the applet. The count is stored using a random-access file. When the applet is loaded, the server reads the count from the file, increases it, and saves it back to the file. Rewrite the program to improve its performance. Read the count from the file when the server starts, and save the count to the file when the server stops, using the Stop button, as shown in Figure 25.24. When the server is alive , use a variable to store the count. Name the client Exercise25_4Client and the server Exercise25_4Server. The client program should be the same as in Listing 25.5. Rewrite the server as a GUI application with a Stop button that exits the server.
Figure 25.24. The applet displays how many times this Web page has been accessed. The server stores the count.

25.5 ( Creating a stock ticker in an applet ) Write an applet like the one in Exercise 16.16 (Simulating a stock ticker). Ensure that the applet gets the stock index from a file stored on the Web server. Enable the applet to run standalone.

Sections 25.6 “25.8

25.6 ( Displaying and adding addresses ) Develop a client/server application to view and add addresses, as shown in Figure 25.25.
  • Declare an Address class to hold name, street, city, state, and zip in an object.


    [Page 859]
  • The user can use the buttons First , Next , Previous , and Last to view an address, and the Add button to add a new address.

  • (Optional) Limit the concurrent connections to two clients.

Figure 25.25. You can view and add an address in this applet.


Name the client Exercise25_6Client and the server Exercise25_6Server.

25.7* ( Retrieving remote files ) Revise Listing 25.10, ViewRemoteFile.java, to use JEditorPane instead of JTextArea .
25.8* ( Using JEditorPane ) Write a program to get descriptions of the layout manager from an HTML file and display it in a JEditorPane , as shown in Figure 25.26. The descriptions are stored in three files: FlowLayout.html, GridLayout.html, and BoxLayout.html.
Figure 25.26. The HTML files are displayed in a JEditorPane .


25.9* ( Web browser ) Modify Listing 25.11, WebBrowser.java, as follows :
  • It accepts an HTML file from a local host. Assume that a local HTML filename begins neither with http:// nor with www.

  • It accepts a remote HTML file. A remote HTML filename begins with either http:// or www.

Section 25.9

25.10** ( Chat ) Write a program that enables two users to chat. Implement one user as the server (Figure 25.27(a)) and the other as the client (Figure 25.27(b)). The server has two text areas: one for entering text and the other (noneditable) for displaying text received from the client. When the user presses the Enter key, the current line is sent to the client. The client has two text areas: one for receiving text from the server, and the other for entering text. When the user presses the Enter key, the current line is sent to the server. Name the client Exercise25_10Client and the server Exercise25_10Server.
[Page 860]
Figure 25.27. The server and client send and receive text from each other.

Section 25.10 Datagram Socket

25.11** ( Loan server using datagram ) Rewrite Exercise 25.1 using datagram sockets.
25.12* ( Multiple clients using datagram ) Rewrite Exercise 25.3 using datagram sockets.
25.13* ( Web visit count using datagram ) Rewrite Exercise 25.4 using datagram sockets.
25.14** ( Displaying and adding addresses using datagrams ) Rewrite Exercise 25.6 using datagram sockets.
25.15** ( Chat using datagrams ) Rewrite Exercise 25.10 using datagram sockets.
 


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