Java Reference
In-Depth Information
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
import java.net.*;
/** Demonstration of reading a local file with a URL. **/
public class
ReadFileViaURL
extends JApplet
implements ActionListener
{
// A Swing text area for display of string info
JTextArea fTextArea;
String fFileToRead
="
data.txt
"
;
StringBuffer fBuf;
// Flag for whether the applet is in a browser
// or running via the main () below.
boolean fInBrowser
=
true;
/** Build the GUI. **/
public void init ()
{
// Create a User Interface with a text area with
// scroll bars and a Go button to initiate processing
// and a Clear button to clear the text area.
Container content
-
pane
=
getContentPane ();
JPanel panel = new JPanel (new BorderLayout ());
// Create a text area to display file contents.
fTextArea = new JTextArea ();
fTextArea.setEditable (false);
// Add to a scroll pane so that a long list of
// computations can be seen.
JScrollPane area
-
scroll
-
pane
=
new JScrollPane
(fTextArea);
panel.add (area
-
scroll
-
pane, BorderLayout.CENTER);
JButton go
-
button
=
new JButton (
"
Go
"
);
go
-
button.addActionListener (this);
JButton clear
-
button
=
new JButton (
"
Clear
"
);
clear
-
button.addActionListener (this);
Search WWH ::
Custom Search