Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- public class rawr implements ActionListener{
- private char[] password={'l','o','l','1','2','3'};
- private JPasswordField passwordField=null;
- public static void main(String[] args){
- JPasswordField pass = new JPasswordField("", 0);
- rawr x = new rawr(pass);
- pass.setEchoChar('*');
- JButton but = new JButton("Check Pass");
- JFrame f = new JFrame("Password Example");
- f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
- f.setLayout(new GridLayout(1, 2));
- but.addActionListener(x);
- f.add(pass);
- f.add(but);
- f.pack();
- f.setVisible(true);
- }
- public rawr(JPasswordField pf){
- passwordField=pf;
- }
- private boolean checkPass(){
- char[] cc = passwordField.getPassword();
- if(cc.length==password.length){
- for(int i=0;i<cc.length;i++){
- try{
- if(cc[i]==password[i]){
- cc[i]=' ';
- }else{
- return false;
- }
- }catch(IndexOutOfBoundsException ex){
- if(cc[i]!=' '){
- return false;
- }
- }
- }
- return true;
- }
- return false;
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(checkPass()){
- }
- if(checkPass()){
- JOptionPane.showMessageDialog(null, "Password is Correct!");
- }else{
- JOptionPane.showMessageDialog(null, "Password is Incorrect, YOU FOOL!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement