URLViewer
Example 5.6 is an improved version of the
URLViewer
you first encountered in Chapter 2. This is a
simple application that provides a window in which you can view the
contents of a URL. It assumes that those contents are more or less
ASCII text. (In future chapters, I’ll remove that restriction.)
Figure 5.1 shows the result. Our application has a
text area in which the user can type a URL, a Load button that the
user uses to load the specified URL, and a
StreamedTextArea
component that displays the text
from the URL. Each of these corresponds to a field in the
URLViewer
class.
Figure 5-1. The URLViewer
Example 5-6. The URLViewer Program
import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import com.macfaq.awt.*; import com.macfaq.io.*; public class URLViewer extends Frame implements WindowListener, ActionListener { TextField theURL = new TextField(); Button loadButton = new Button("Load"); StreamedTextArea theDisplay = new StreamedTextArea(); public URLViewer() { super("URL Viewer"); } public void init() { this.add("North", theURL); this.add("Center", theDisplay); Panel south = new Panel(); south.add(loadButton); this.add("South", south); theURL.addActionListener(this); loadButton.addActionListener(this); this.addWindowListener(this); this.setLocation(50, 50); this.pack(); this.show(); } public void actionPerformed(ActionEvent evt) { try { URL ...
Get Java I/O now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.