import java.awt.*;
import java.awt.event.*;

public class FileWindow extends Frame implements ActionListener
{
public application app;
public TextField   filetext;
public Button      ok;
public Button      cancel;
    
public FileWindow(String title, int sx, int sy, application ap)
    {
        super(title);
        app = ap;
        setSize(sx, sy);
        setLayout(new GridLayout(2, 1));
        filetext = new TextField();
        filetext.addActionListener(this);
        add(filetext);
	
        Panel buttonpanel = new Panel(new GridLayout(1, 2));
        ok = new Button("Ok");
        ok.addActionListener(this);
        cancel = new Button("Cancel");
        cancel.addActionListener(this);
        buttonpanel.add(ok);
        buttonpanel.add(cancel);
        add(buttonpanel);
    }
    
public void actionPerformed(ActionEvent event)
    {
        if(event.getSource() == filetext)
	    {
		setVisible(false);
		if(getTitle().equals("Open File"))
		    app.read(filetext.getText());
		else
		    app.write(filetext.getText());
		filetext.setText("");
	    }
        else if(event.getSource() == ok)
	    {
		setVisible(false);
		if(getTitle().equals("Open File"))
		    app.read(filetext.getText());
		else
		    app.write(filetext.getText());
		filetext.setText("");
	    }
        else if(event.getSource() == cancel)
	    {
		setVisible(false);
		filetext.setText("");
	    }
    }
}


