by Dinesh Thakur Category: Swing

 

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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article