26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 17 Networking 1061<br />

• The HTTP pro<strong>to</strong>col (Hypertext Transfer Pro<strong>to</strong>col) that forms the basis of the World Wide Web<br />

uses URIs (Uniform Resource Identifiers, also called URLs or Uniform Resource Loca<strong>to</strong>rs) <strong>to</strong> locate<br />

data on the Internet. Common URIs represent files or direc<strong>to</strong>ries and can represent complex<br />

tasks such as database lookups and Internet searches.<br />

• Web browsers often restrict an applet so that it can communicate only with the machine from<br />

which it was originally downloaded.<br />

• A Hashtable s<strong>to</strong>res key/value pairs. A program uses a key <strong>to</strong> s<strong>to</strong>re and retrieve an associated<br />

value in the Hashtable. Hashtable method put takes two arguments—a key and its associated<br />

value—and places the value in the Hashtable at a location determined by the key. Hashtable<br />

method get takes one argument—a key—and retrieves the value (as an Object<br />

reference) associated with the key.<br />

• A Vec<strong>to</strong>r is a dynamically resizable array of Objects. Vec<strong>to</strong>r method addElement adds<br />

a new element <strong>to</strong> the end of the Vec<strong>to</strong>r.<br />

• Applet method getAppletContext returns a reference <strong>to</strong> an AppletContext object that<br />

represents the applet’s environment (i.e., the browser in which the applet is executing).<br />

• AppletContext method showDocument receives a URL object as an argument and passes it<br />

<strong>to</strong> the AppletContext (i.e., the browser), which displays the World Wide Web resource associated<br />

with that URL.<br />

• A second version of AppletContext method showDocument enables an applet <strong>to</strong> specify the<br />

target frame in which Web resource should be displayed. Special target frames include _blank<br />

(display the content from the specified URI in a new Web browser window), _self (display the<br />

content from the specified URI in the same frame as the applet) and _<strong>to</strong>p (the browser should<br />

remove the current frames, then display the content from the specified URI in the current window).<br />

• Component method setCursor changes the mouse cursor when the cursor is positioned over<br />

a specific GUI component. The Cursor construc<strong>to</strong>r receives an integer indicating the cursor type<br />

(such as Cursor.WAIT_CURSOR or Cursor.DEFAULT_CURSOR).<br />

• JEdi<strong>to</strong>rPane method setPage downloads the document specified by its argument and displays<br />

it in the JEdi<strong>to</strong>rPane.<br />

• Typically, an HTML document contains hyperlinks—text, images or GUI components that, when<br />

clicked, link <strong>to</strong> another document on the Web. If an HTML document is displayed in a JEdi<strong>to</strong>r-<br />

Pane and the user clicks a hyperlink, the JEdi<strong>to</strong>rPane generates a HyperlinkEvent<br />

(package javax.swing.event) and notifies all registered HyperlinkListeners (package<br />

javax.swing.event) of that event.<br />

• HyperlinkEvent method getEventType determines the type of the HyperlinkEvent.<br />

Class HyperlinkEvent contains public static inner class EventType, which defines<br />

three hyperlink event types: ACTIVATED (user clicked a hyperlink), ENTERED (user moved the<br />

mouse over a hyperlink) and EXITED (user moved the mouse away from a hyperlink).<br />

• HyperlinkEvent method getURL obtains the URL represented by the hyperlink.<br />

• Stream-based connections are managed with Socket objects.<br />

• AServerSocket object establishes the port where a server waits for connections from clients.<br />

The second argument <strong>to</strong> the ServerSocket construc<strong>to</strong>r specifies the number of clients that can<br />

wait for a connection and be processed by the server. If the queue of clients is full, client connections<br />

are refused. The ServerSocket method accept waits indefinitely (i.e., blocks) for a<br />

connection from a client and returns a Socket object when a connection is established.<br />

• Socket method getOutputStream gets a reference <strong>to</strong> the OutputStream associated with<br />

a Socket. Socket method getInputStream gets a reference <strong>to</strong> the InputStream associated<br />

with the Socket.

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

Saved successfully!

Ooh no, something went wrong!