码迷,mamicode.com
首页 > 其他好文 > 详细

验证码窗口

时间:2020-10-06 20:12:30      阅读:27      评论:0      收藏:0      [点我收藏+]

标签:style   ace   char   orm   color   exti   oid   png   pre   

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);
        }
    }
}

技术图片

 

 技术图片

 

验证码窗口

标签:style   ace   char   orm   color   exti   oid   png   pre   

原文地址:https://www.cnblogs.com/feng747/p/13771580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!