package Robot;

/* TVException.java
 *
 * Created on June 27, 2005, 10:42 AM
 *
 * This class is a dialog box that appears whenever an error
 * or exception is caught.
 *
 *  Author: Michael A. Piskuric (2537405) Summer 2005
 */

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

public class TVException extends JDialog implements ActionListener {
    
    // Creates a dialog box that displays a string error message
    public TVException(String error) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
        setTitle("Error");
        setLayout(new GridLayout(2,1));        
        JTextArea text = new JTextArea(error);
        text.setBackground(getContentPane().getBackground());
        text.setEditable(false);       
        JButton ok = new JButton("OK");
        ok.addActionListener(this);
        add(text);
        JPanel panel = new JPanel();
        panel.add(ok);
        add(panel);
        pack();
        int x = ((int)screenSize.getWidth()/2)-(getWidth()/2);
        int y = ((int)screenSize.getHeight()/2)-(getHeight()/2);
        setLocation(x,y);
        setVisible(true);
    }

    // close window when button clicked
    public void actionPerformed(ActionEvent e) {
        JButton temp = (JButton)e.getSource();
        if(temp.getText() == "OK"){
            dispose();
        }
    }
}   // end TVException
