自动生成MyEclipse8.5的注册码

        今天打开MyEclipse的时候,系统提示注册好像快到期了(因为没有花钱嘛,所以之前就从网上找了一个注册码用着安静)。于是又找了几个发现还是不行,后来发现使用代码直接生成的很好用,从哪里找的忘记看了,这里很感谢共享出来的朋友。

        自己闲着没事,就在代码外面加了一个界面,核心代码没改,当然,也不会改快哭了

package org.ygy.create;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

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

class CreateMyEclipseCode {
	private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.";

	public CreateMyEclipseCode() {
		super();
	}
	
	public String getCode(String userId, String licenseNum) {
		Calendar calendar = Calendar.getInstance();
		calendar.add(1, 3);
		calendar.add(6, -1);
		
		NumberFormat numberFormat = new DecimalFormat("000");
		licenseNum = numberFormat.format(Integer.valueOf(licenseNum));
		String verTime = new StringBuilder("-").append(
				new SimpleDateFormat("yyMMdd").format(calendar.getTime()))
				.append("0").toString();
		String type = "YE3MP-";
		String need = new StringBuilder(userId.substring(0, 1)).append(type)
				.append("300").append(licenseNum).append(verTime).toString();
		String dx = new StringBuilder(need).append(LL).append(userId).toString();
		int suf = this.decode(dx);
		String code = new StringBuilder(need).append(String.valueOf(suf)).toString();
		
		return this.change(code);
	}

	private int decode(String s) {
		int i;
		char[] ac;
		int j;
		int k;
		i = 0;
		ac = s.toCharArray();
		j = 0;
		k = ac.length;
		while (j < k) {
			i = (31 * i) + ac[j];
			j++;
		}
		return Math.abs(i);
	}

	private String change(String s) {
		byte[] abyte0;
		char[] ac;
		int i;
		int k;
		int j;
		abyte0 = s.getBytes();
		ac = new char[s.length()];
		i = 0;
		k = abyte0.length;
		while (i < k) {
			j = abyte0[i];
			if ((j >= 48) && (j <= 57)) {
				j = (((j - 48) + 5) % 10) + 48;
			} else if ((j >= 65) && (j <= 90)) {
				j = (((j - 65) + 13) % 26) + 65;
			} else if ((j >= 97) && (j <= 122)) {
				j = (((j - 97) + 13) % 26) + 97;
			}
			ac[i] = (char) j;
			i++;
		}
		return String.valueOf(ac);
	}

}

public class CreateMyEclipseCodeFrame extends JFrame{
	private static final long serialVersionUID = -4520877838812964472L;
	
	private static final int WIDTH = 550;
	private static final int HEIGHT = 150;
	
	private Container container = null;
	private JLabel inputLabel = null;
	private JLabel resultLabel = null;
	private JTextField inputText = null;
	private JTextField resultText = null;
	private JButton createButton = null;
	private JButton clearButton = null;
	
	public CreateMyEclipseCodeFrame() {
		super("生成MyEclipse8.5注册码");
		
		//设置居中显示
		Toolkit tool = Toolkit.getDefaultToolkit();
		setSize(WIDTH ,  HEIGHT);
		setLocation( (tool.getScreenSize().width - WIDTH ) / 2 , (tool.getScreenSize().height - HEIGHT) / 2);
		setResizable(false);
		
		container = this.getContentPane();
		container.setLayout(new FlowLayout());
		
		
		inputLabel = new JLabel("请输入账户名(Subscriber):");
		container.add(inputLabel);
		
		inputText = new JTextField(20);
		container.add(inputText);
		
		//生成注册码按钮
		createButton = new JButton("生成注册码");
		createButton.addActionListener(new CreateListener());
		container.add(createButton);
		
		resultLabel = new JLabel("注册码(Subscription Code):");
		container.add(resultLabel);
		
		resultText = new JTextField(30);
		container.add(resultText);
		
		//清空按钮
		clearButton = new JButton("清空");
		clearButton.addActionListener(new ClearListener());
		container.add(clearButton);
		
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	/**
	 * 生成注册码的监听器
	 * 
	 * @author ygy
	 *
	 */
	class CreateListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			String name = inputText.getText();
			
			if(name.trim().equals("")) {
				JOptionPane.showMessageDialog(CreateMyEclipseCodeFrame.this, "账户不能为空!", "错误提示", JOptionPane.ERROR_MESSAGE);
			} else {
				CreateMyEclipseCode create = new CreateMyEclipseCode();
				String code = create.getCode(name, "5");
				
				resultText.setText(code);
			}
		}
		
	}
	
	/**
	 * 清空
	 * 
	 * @author ygy
	 *
	 */
	class ClearListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			inputText.setText("");
			resultText.setText("");
		}
		
	}
	
	public static void main(String[] args) {
		new CreateMyEclipseCodeFrame();
	}
}

你可能感兴趣的:(自动生成MyEclipse8.5的注册码)