验证码窗口

package 大大大;
import java.util.Random;
import javax.swing.JOptionPane;
import javax.swing.*;
public class kuang {
    public static void main(String[] args) {
        JTextField name=new JTextField(5);
        JTextField x=new JTextField(5);
        JTextField key=new JTextField(5);
        JPanel myPanel=new JPanel();
        StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        StringBuffer sb = new StringBuffer();
        Random r = new Random();
        JTextField yanzhengma=new JTextField(5);
        int range = buffer.length();
        for (int i = 0; i <4 ; i++) {
            sb.append(buffer.charAt(r.nextInt(range)));
        }
        myPanel.add(new JLabel("账号:"));
        myPanel.add(name);
        myPanel.add(Box.createHorizontalStrut(15));//a spacer
        myPanel.add(new JLabel("密码:"));
        myPanel.add(key);
        myPanel.add(Box.createHorizontalStrut(15));//a spacer
        
        myPanel.add(new JLabel("请输入验证码:"));
        myPanel.add(yanzhengma);
        myPanel.add(Box.createHorizontalStrut(15));//a spacer
        myPanel.add(new JLabel("验证码为:"+sb));
         JOptionPane.showConfirmDialog(null, myPanel,"Please Enter name and key ", JOptionPane.OK_CANCEL_OPTION);

            if (yanzhengma.getText().toString().equals(sb.toString())) {
                JOptionPane.showMessageDialog(null, "验证码成功", "验证", JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(null, "验证码错误", "验证", JOptionPane.INFORMATION_MESSAGE);
        }
    }
}

 

 

 

posted @ 2020-10-05 21:04  陈涵  阅读(111)  评论(0编辑  收藏  举报