标签:tin and int pass buffer you number exti content
package yzm; import java.util.Random; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.ImageIcon;//顶级容器即空白窗口 import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Test { public static void main(String[] args) { Test t=new Test(); t.set(); } private void set() { JFrame f=new JFrame(); f.setTitle("验证码");//窗口标题 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭 f.setExtendedState(JFrame.MAXIMIZED_VERT);//最大化 f.setSize(300,300);//窗口大小 Container con=f.getContentPane(); JPanel pan=new JPanel(); JLabel yan=new JLabel("验证码:"); pan.add(yan); JTextField yanzhengma=new JTextField(10); pan.add(yanzhengma); String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer yzm = new StringBuffer(); for (int i = 0; i < 4; ++i) { int number = random.nextInt(62);// [0,62) yzm.append(str.charAt(number)); } String s=yzm.toString(); JLabel ma=new JLabel(s); pan.add(ma); JButton buttenOne=new JButton("确定"); pan.add(buttenOne); con.add(pan); f.setVisible(true); //窗口实现 } }
标签:tin and int pass buffer you number exti content
原文地址:https://www.cnblogs.com/zmh-980509/p/9751793.html