import java.awt.*;
import java.applet.*;

public class create_key extends Frame {
    boolean inAnApplet = true;
	static drawCanvas top=new drawCanvas();
	static drawCanvas front=new drawCanvas();
String keyfilename;	

static TextField statusline=new TextField("Ready",0);

    public create_key () {
        setLayout(new BorderLayout());
	
        add("North",top);
        add("South",front);
	add("West",new Button("Clear"));
	add("East",new Button("Ready"));	
	add("Center",statusline);
    }

    public boolean action(Event event, Object arg) {
	int i;

	if (event.target instanceof Button){
		if (((String)arg).equals("Ready")) {
		if (top.startwrite()){
String curdir=System.getProperty("user.dir");
FileDialog fd = new FileDialog(this, "Please specify the name of the keyfile",1);
	fd.setDirectory(curdir);
	fd.show();
	if (fd.getFile()!=null){
System.out.println(fd.getDirectory() + fd.getFile());
keyfilename=fd.getDirectory() + fd.getFile();
new cr_writekey(keyfilename,top.txp,top.typ,front.fxp,front.fyp,top.txoffset);
create_key.keyfilename=keyfilename;
create_key.statusline.setText("keyfile is ready");
			dispose();
			top.pucol();
			front.pucol();      	
			return true;
	}else statusline.setText("please specify a valid filename");
            	}
		}
		if (((String)arg).equals("Clear")) {
		top.pucol();
		front.pucol();	
		}
	}	
        if (event.target instanceof MenuItem) {
            if (((String)arg).equals("fff")) {
//                FileDialog fd = new FileDialog(this, "FileDialog");
//                fd.show();
            }
        }
        return true;
    }

    public boolean handleEvent(Event event) {
        //If we're running as an application, closing the window
        //should quit the application.
        if (event.id == Event.WINDOW_DESTROY) {
            if (inAnApplet) {
                dispose();
            } else {
                Component c[] = getComponents();
		for(int x=0;x<c.length;x++)
		   c[x].handleEvent(event);
		dispose();
		top.pucol();
		front.pucol();
        	
		return false;
            }
        }
        return super.handleEvent(event);
    }



/*    public static void main(String args[]) {
        create_key window = new create_key();
        window.inAnApplet = false;

        window.setTitle("Cryptogram - key-file creator");
        window.pack();
        window.show();
    }*/

}



