java编写MyEclipse注册机

来源:互联网 发布:dota2最新比赛数据 编辑:程序博客网 时间:2024/06/05 09:10

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class MyEclipeSubscription extends JFrame implements ActionListener {
private static final long serialVersionUID = 8326142080613812520L;
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.";
private JTextField subscriber, subsccode, lic;
private JComboBox prosta;

public MyEclipeSubscription() {
  super("MyEclipse注册机(Billows制作)");
  init();
}

private void init() {
  this.setVisible(true);
  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.setSize(new Dimension(350, 250));
  this.setResizable(false);
  Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  int h = (int) d.getHeight() / 4;
  int w = (int) d.getWidth() / 4;
  this.setLocation(w, h);

  Container c = this.getContentPane();
  JPanel north = new JPanel();
  north.add(new JLabel("Subscriber:"));
  subscriber = new JTextField("Billows", 35);
  north.add(subscriber);
  c.add(north, BorderLayout.NORTH);

  JPanel center = new JPanel();
  center.add(new JLabel("Lic(1-999):"));
  lic = new JTextField("666", 35);
  center.add(lic);

  center.add(new JLabel("pro OR sta:"));
  prosta = new JComboBox();
  prosta.addItem("MyEclipse Professional Subscript");
  prosta.addItem("MyEclipse Standard Subscription");
  center.add(prosta);

  center.add(new JLabel("Subsc Code:"));
  subsccode = new JTextField(35);
  subsccode.setEditable(false);
  center.add(subsccode);

  JTextArea jta = new JTextArea();
  jta.setFont(new Font("", Font.PLAIN, 12));
  jta.setBackground(Color.LIGHT_GRAY);
  jta.setText("\n作者:Billows.Van\nEmail(MSN):haidii@126.com\nQQ:417616683");
  jta.setEditable(false);
  center.add(jta);
  c.add(center, BorderLayout.CENTER);

  JButton ok = new JButton("获取Subscription Code");
  c.add(ok, BorderLayout.SOUTH);
  ok.addActionListener(this);
  this.validate();
}

public String getSerial(String userId, String licenseNum, int prosta) {
  Calendar cal = Calendar.getInstance();
  cal.add(1, 3);
  cal.add(6, -1);
  NumberFormat nf = new DecimalFormat("000");
  try {
   licenseNum = nf.format(Integer.valueOf(licenseNum));
  } catch (Exception e) {
   JOptionPane.showMessageDialog(this, "请在lic中请输入数字!");
  }

  String verTime = new StringBuilder("-").append(new java.text.SimpleDateFormat("yyMMdd").format(cal.getTime())).append("0").toString();
  String type = "YE3MP-";// "E2MY"
  if (prosta == 1)
   type = "YE2MY-";
  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 static void main(String[] args) {
  try {
   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   @SuppressWarnings("unused")
   MyEclipeSubscription myeclipsegen = new MyEclipeSubscription();
  } catch (Exception e) {
   e.printStackTrace();
  }
}

/*
  * (non-Javadoc)
  *
  * @see
  * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
public void actionPerformed(ActionEvent e) {
  String s = getSerial(subscriber.getText(), lic.getText(), prosta.getSelectedIndex());
  subsccode.setText(s);

}

}

 

转自:http://hi.baidu.com/changjyzzu/item/5eb0e285aa481650840faba4