28.2 Reading a File on a Web Server

The application in Fig. 28.1 uses Swing GUI component JEditorPane (from package javax.swing) to display the contents of a file on a web server. The user enters a URL in the JTextField at the top of the window, and the application displays the corresponding document (if it exists) in the JEditorPane. Class JEditorPane is able to render both plain text and basic HTML-formatted text, as illustrated in the two screen captures (Fig. 28.2), so this application acts as a simple web browser. The application also demonstrates how to process HyperlinkEvents when the user clicks a hyperlink in the HTML document.

 1   // Fig. 28.1: ReadServerFile.java  2   // Reading a file by opening a ...

Get Java™ How To Program (Early Objects), Tenth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.