import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

    // Display the contents of a file in a scrolling text area.
class SwingTextFrame2 extends JFrame {
    public SwingTextFrame2() {
        final int width = 300, height = 300;
        setSize(width,height);
        Container contents = getContentPane();

        // Add a text area wrapped in a scroll pane.
        JScrollPane scroller = new JScrollPane(getText());
        contents.add(scroller,"Center");

        contents.add(new QuitJButton(),"South");
    }

        // Show the given file in the text area.
    public void showFile(String filename){
        try{
            FileReader infile = new FileReader(filename);
            getText().read(infile,null);
            infile.close();
        }
        catch(IOException e){
            JOptionPane.showMessageDialog(
                    getContentPane(),
                    e.toString(),
                    "File Failure",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    protected JTextArea getText(){
        return text;
    }

    // The text area used to display the file.
    private final JTextArea text = new JTextArea();
}
