/***********************************************************************
** This an example of Applet with secure data
************************************************************************/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class SecureInformationApplet   extends Applet 
                                implements TextListener

{
   TextField    userNameTextField;
   TextField    userPasswordTextField;
   TextField    TextField_1;
   String       stringValue;
   String       userName = "";
   String       userPassword = "";
   Label        userNameLabel;
   Label        userPasswordLabel;
   Label        prompt_1_Label;
   Label        prompt_2_Label;
   Checkbox     savePasswordCheckbox;


   public void init()
   {
      SetupCommonFeature("Applet test");
      setLayout(null);
      userNameLabel         = new Label("User name:");
      userPasswordLabel     = new Label("User password:");
      prompt_1_Label        = new Label("Please enter your user name and password");
      prompt_2_Label        = new Label("Save this password in your your password list");
      userNameTextField     = new TextField();
      userPasswordTextField = new TextField();
      TextField_1           = new TextField();
      savePasswordCheckbox  = new Checkbox();
      //===========================
      prompt_1_Label.setBounds(30,20,240,30);
      userNameLabel.setBounds(30,150,100,20);
      userPasswordLabel.setBounds(10,180,100,20);
      userNameTextField.setBounds(110,150,100,20);
      userPasswordTextField.setBounds(110,180,100,20);
      savePasswordCheckbox.setBounds(20,220,20,20);
      prompt_2_Label.setBounds(40,220,250,30);
      TextField_1.setBounds(10,260,100,20);

      //===========================
      userNameTextField.setBackground(Color.white);
      userPasswordTextField.setBackground(Color.white);
      userNameTextField.addTextListener(this);
      userPasswordTextField.addTextListener(this);
      userPasswordTextField.setEchoChar('*');
      //===========================
      add(TextField_1);
      add(userNameTextField);
      add(userPasswordTextField);
      add(userNameLabel);
      add(userPasswordLabel);
      add(prompt_1_Label);
      add(prompt_2_Label);
      add(savePasswordCheckbox);
      show();

   }
  //----------------------------------------------------
   private void SetupCommonFeature(String FrameTitle)
   {
     setBackground(Color.lightGray);
   }
  //----------------------------------------------------
  public void textValueChanged(TextEvent PassedTextEvent)
  {

     TextField LocalTextField = (TextField)PassedTextEvent.getSource();
     if(LocalTextField.equals(userNameTextField))
     {
       userName = "Name: ";
       userName += LocalTextField.getText();
       TextField_1.setText(userName);
       stringValue = userName;
     }
     else
       if(LocalTextField.equals(userPasswordTextField))
       {
         userPassword = "Password: ";
         userPassword += LocalTextField.getText();
         StringBuffer reverseStringB = (new StringBuffer(userPassword)).reverse();
         userPassword = new String(reverseStringB);
         TextField_1.setText(userPassword);
         stringValue = userPassword;
       }
  }
   //----------------------------------
   public void paint(Graphics MyGraphics)
   {
     TextField_1.setText(stringValue);
   }
   //----------------------------------
   public String getUserName()
   {
      return(userName);
   }
   //----------------------------------
   public String getUserPassword()
   {
      return(userPassword);
   }
}
