
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


/** An instance is a window with text */
public class TextWindow extends JFrame {
    
    /** Constructor: A window with title and a noneditable text area
        and an Ok button to close it.
        The text area is cols columns wide */
    public TextWindow(String text, String title, int cols) {
        Container contents= getContentPane();
        setTitle(title);
        contents.add(BorderLayout.NORTH,new JLabel(title));
        
        // add text field
        JTextArea textArea= new JTextArea(text, 6, cols);
        textArea.setEditable(false);
        contents.add(BorderLayout.CENTER,textArea);
        
        // add ok button
        JButton ok= new JButton("Ok");
        ok.addActionListener(new OkActionListener());
        contents.add(BorderLayout.SOUTH,ok);
        
        // add window closing event handler
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                closeWindow();
            }});
            
        // finalize frame
        pack();
        setVisible(true);
    }
    
    
    /** Dispose of the window */
    public void closeWindow() {
        dispose();
    }
    
    /** Handle press of button ok -- dispose of the window */
    class OkActionListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            closeWindow();
        }
    }
}


