此文章是vip文章,如何查看?  

1,点击链接获取密钥 http://nicethemes.cn/product/view29882.html

2,在下方输入文章查看密钥即可立即查看当前vip文章


CDKEY生成器

  • 时间:
  • 浏览:
  • 来源:互联网

CDKEY  生成器  


无聊 写着好玩的.

package randomString;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main {

	/**
	 * 生成随机字符串
	 */
	private JFrame jFrame;
	private JPanel jp;
	private JButton jb;
	private JTextField tf,tf2;
	private JLabel	jl;
	public Main(){
		jFrame = new JFrame("字符串生成工具  by:smile");
		jp = new JPanel();
		jb = new JButton("生成(s)");
		tf = new JTextField(20);
		tf2 = new JTextField(3);
		jl = new JLabel("位");
		MyActionListener mal = new MyActionListener();

		jp.add(tf);
		jp.add(jb);
		jp.add(tf2);
		jp.add(jl);
		jFrame.add(jp);

		jb.setMnemonic('s');
		jb.addActionListener(mal);
		
		jFrame.pack();
		int w = jFrame.getToolkit().getScreenSize().width;//宽度
		int h = jFrame.getToolkit().getScreenSize().height;//高度
		jFrame.setLocation(w/2-200,h/2-30);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setVisible(true);
	}
	class MyActionListener implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource().equals(jb)){
				try {
					tf.setText(Main.getRandomString(Integer.parseInt(tf2.getText())));
				} catch (Exception x) {
					JOptionPane.showMessageDialog(null, "请输入数字");
				}
			}
		}
	}
	public static String getRandomString(int length) { //length表示生成字符串的长度
		String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";   
		Random random = new Random();   
		StringBuffer sb = new StringBuffer();   
		for (int i = 0; i < length; i++) {   
			int number = random.nextInt(base.length());   
			sb.append(base.charAt(number));   
		}   
		return sb.toString();
	}  
	public static void main(String[] args) {
		new Main();
	}
}




本文链接http://element-ui.cn/news/show-576772.aspx