by Dinesh Thakur

 

import java.awt.*;

import javax.swing.*;
import java.awt.event.*;
public class JavaExamplePasswordInJApplet extends JApplet
  {
    String CrPswrd = "Open Sesame";
    JPasswordField PswrdFld = new JPasswordField(10);
    public void init()
      {
        Container Cntnr = getContentPane();
        Cntnr.setLayout(new FlowLayout());
        Cntnr.add(new JLabel("Type Password:"));
        Cntnr.add(PswrdFld);
        PswrdFld.setEchoChar('*');
        PswrdFld.addActionListener(new ActionListener()
            {
                 public void actionPerformed(ActionEvent e1)
                 {
                          String Inpt = new String(PswrdFld.getPassword());
                          if(CrPswrd.equals(Inpt))
                      showStatus("Correct Password");
                          else
                          showStatus("Wrong Password");
                     }
           });
       }
}
/*<APPLET CODE=JavaExamplePasswordInJApplet.class WIDTH=370 HEIGHT=300></APPLET>*/
JPasswordField Java Example