import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;

public class registerApplet extends Applet implements ActionListener {

  Label     label1,label2;
  TextField text1,text2;

  Button okButton=new Button("Ok");
  Button cancelButton=new Button("Cancel");

  String value1,value2;

  //public registerApplet() {
  //  super();
  //}

  public void init() {
      value1=new String("");
      value2=new String("");
      label1=new Label("UserName");
      label2=new Label("Password");
      text1=new TextField(10);
      text2=new TextField(10);
      okButton=new Button("OK");
      cancelButton=new Button("Cancel");

      setLayout(new BorderLayout() );

      Panel p1=new Panel();
      p1.setLayout(new GridLayout(2,2,0,5) );
      p1.add(label1);
      p1.add(text1);

      p1.add(label2);
      p1.add(text2);

      text2.setEchoChar('*'); // for password use

      Panel p2=new Panel();
      p2.setLayout(new FlowLayout(FlowLayout.CENTER));
      p2.add(okButton);
      p2.add(cancelButton);

      // add event listeners
      okButton.addActionListener(this);
      cancelButton.addActionListener(this);

      text2.addActionListener(this);

      //this.setEnabled(true);
      text1.setEnabled(true);  // enable editing of text1

      this.add("North",p1);
      this.add("South",p2);
      //this.pack();

      //this.show();

  }

  public void actionPerformed(ActionEvent e) {

     Object esource=e.getSource();

    if ( (esource == okButton) || (esource ==text2) ) {
        // error checking and setting the value
        value1=text1.getText();
        if ( value1.equals("") ) return;// true;
        value2=text2.getText();
        this.setVisible(false);

        value1=StrLock.encript(value1);
        value2=StrLock.encript(value2);
        String address=getParameter(GraphDomainServlet.URL_PARAM);
        address=address+value1+"?"+GraphDomainServlet.PASS_PARAM+"="+value2;
        System.out.println("Show content:"+address);
        URL newurl=null;
        try {
         newurl=new URL(address);
         (getAppletContext()).showDocument(newurl);
        } catch (MalformedURLException e2) {
            System.out.println("Mal URL");
        }

        return;// true;
    }  else if (esource == cancelButton) {
        value1=null;
        value2=null;
        //this.setVisible(false);
        return ;//true;
     }
   return;// false;


  }

}

