⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registration.java

📁 这个小软件( RealEditor )是同学一起编写的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ecust.mainframe;

import com.ecust.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.*;


public class Registration {
    
    private static RegistrationDetails rd = new RegistrationDetails(); 
    
    private static File registrationFile = 
        new File( "C:/Documents and Settings/All Users/Application Data/RealEditor/registrationDetails.rd" );
    
    public static File getRegistrationFile() {
        return registrationFile;
    }
    
    public static String getName() {
        
        RegistrationDetails savedRd = getRegistrationDetails();
        
        if ( savedRd == null ) {
            return "nobody";
        } else {
            return savedRd.getName();
        }
        
    }
    
   public static void setStarted( boolean started ) {
       RegistrationDetails savedRd = getRegistrationDetails();
       
       savedRd.setStarted( started );
       saveRegistrationDetails( savedRd );
       

   }
   
    
    public static void  register() {
        
        final JFrame registrationFrame = new JFrame( "RealEditor Registration" );
        
        registrationFrame.addWindowListener(
                new WindowAdapter() {
                    public void windowClosing( WindowEvent e ) {
                        Registration.setStarted( false );
                    }
                }
        );
        
        final JTextField 
            nameField = new JTextField( 20 ),
            machineCodeField = new JTextField( 20 ),
            keyField = new JTextField( 20 );
        
        machineCodeField.setEditable( false );
        
        machineCodeField.setHorizontalAlignment( JTextField.CENTER );
            
        final JLabel
            statementLabel = new JLabel(),
            nameLabel = new JLabel( "Name :                     " ),
            machineCodeLabel = new JLabel( "Machine Code :      " ),
            keyLabel = new JLabel( "Serial No :                " );
            
        JPanel
            namePanel = new JPanel(),
            machineCodePanel = new JPanel(),
            keyPanel = new JPanel(),
            registrationDetailsPanel = new JPanel(),
            buttonPanel = new JPanel();
        
        registrationDetailsPanel.setLayout( new GridLayout( 3, 1 ) );
        
        namePanel.setBorder( new EtchedBorder( EtchedBorder.LOWERED ) );
        machineCodePanel.setBorder( new EtchedBorder( EtchedBorder.LOWERED ) );
        keyPanel.setBorder( new EtchedBorder( EtchedBorder.LOWERED ) );
        registrationDetailsPanel.setBorder( 
                new TitledBorder( 
                        null, "Registration Details", TitledBorder.DEFAULT_JUSTIFICATION, 
                        TitledBorder.DEFAULT_POSITION, new Font( "Serif", Font.PLAIN, 12 ), Color.GRAY  ) );
        
        JButton
            registerButton = new JButton( "Register" ),
            cancelButton = new JButton( " Cancel " );
        
        Properties prop = System.getProperties();
        
        String properties = 
            mixString( 
                prop.getProperty( "user.name" ), 
                prop.getProperty( "os.arch" ) );
        
        String machineCode = "";
        
        for ( int i = 0; i < properties.length(); i++ ) {
            machineCode += ( int )properties.charAt( i );
        }
        
        if ( machineCode.length() > 17 ) {
            machineCode = Long.toString( Long.parseLong( machineCode.substring( 0, ( int )machineCode.charAt( machineCode.length() / 2 ) % 10 + 8 ) ) ^
            Long.parseLong( machineCode.substring( ( int )machineCode.charAt( machineCode.length() / 2 ) % 10 + 8, machineCode.length() ) ) );
            
        }
        
        machineCodeField.setText( machineCode );
        
        registrationFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        registrationFrame.setSize( 420, 230 );
        registrationFrame.setResizable( false );
        Container container = registrationFrame.getContentPane();
        container.setLayout( new BorderLayout() );
        
        namePanel.add( nameLabel );
        namePanel.add( nameField );
        machineCodePanel.add( machineCodeLabel );
        machineCodePanel.add( machineCodeField );
        keyPanel.add( keyLabel );
        keyPanel.add( keyField );
        buttonPanel.add( registerButton );
        buttonPanel.add( cancelButton );
        
        statementLabel.setHorizontalAlignment( JLabel.CENTER );
        statementLabel.setText( "<html><b><font size = 5 color = Purple>Please Enter Your Registration Details Below.</font></b></html>" );
        registrationDetailsPanel.add( namePanel );
        registrationDetailsPanel.add( machineCodePanel );
        registrationDetailsPanel.add( keyPanel );
        container.add( statementLabel, BorderLayout.NORTH );
        container.add( registrationDetailsPanel, BorderLayout.CENTER );
        container.add( buttonPanel, BorderLayout.SOUTH );
        
        registrationFrame.getRootPane().setDefaultButton( registerButton );
        
        registerButton.addActionListener( 
                new ActionListener() {
                    public void actionPerformed( ActionEvent e ) {
                        String name = nameField.getText();
                        
                        String key = keyField.getText();
                        
                        if ( name.equals( "" ) ) {
                            
                            
                            JOptionPane.showMessageDialog( 
                                        registrationFrame, "Name Is Required!", 
                                        "Registration Failed", JOptionPane.WARNING_MESSAGE   );
                            
                            
                        } else {
                            
                            String pwd = encrypt( name, machineCodeField.getText() );
                            
                            if ( pwd.equals( key ) ) {
                                rd = new RegistrationDetails( name, pwd );                           
                                saveRegistrationDetails( rd );
                                
                                registrationFrame.dispose();
                           
                                JOptionPane.showMessageDialog( 
                                       registrationFrame, "Registration Succeed!",
                                       "Registration Result", JOptionPane.INFORMATION_MESSAGE );
                                
                                
                                
                                new RealEditorFrame();
                                Registration.setStarted( true );
                            } else {
                                Registration.setStarted( false );
                                System.exit( 0 );
                            }
                            
                        }
                        
                        
                        
                    }
                }
        );
        
        
        cancelButton.addActionListener( 
                new ActionListener() {
                    
                    public void actionPerformed( ActionEvent e ) {
                        Registration.setStarted( false );
                        System.exit( 0 );
                    }
                }
        );
        
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        registrationFrame.setLocation( ( screenSize.width - registrationFrame.getWidth() ) / 2,
                ( screenSize.height - registrationFrame.getHeight() ) / 2 );
        
        RegistrationDetails savedRd = null;
           
        if ( !registrationFile.exists() )
            saveRegistrationDetails( rd );
        
        savedRd = getRegistrationDetails();
        
        if ( savedRd != null ) {
            
            if ( !encrypt( savedRd.getName(), machineCodeField.getText() ).equals( savedRd.getKey() ) ) {
                registrationFrame.toFront();
                registrationFrame.setVisible( true );
                
            } else {
                new RealEditorFrame();
            }
                
            
        }
        
        
    }
    
    private static String encrypt( String name, String machineCode ) {
       
        
                
        name = mixString( name, machineCode );
        
        String s = "6";
        
        for ( int i = 0; i < name.length(); i++ ) {
            int asci = name.charAt( i % name.length() );
            s += asci;
        }
        
        if ( s.length() > 17 ) {
            s = s.substring( 0, ( int )name.charAt( name.length() / 2 ) % 10 + 8 );
        }

        long pwdNum = ( long )( Math.floor( 
                Math.pow( 
                        Long.parseLong( s ), 2 ) ) % 
                            Math.floor( Math.pow( 2, 63 ) ) );
        
        String pwd = Long.toString( 
                pwdNum ^ ( long )Math.pow( Long.toString( pwdNum ).length(), 20 ) );
        
        Node firstNode = null;
        Node currentNode = null;
        int j = 0;
        int k = 0;
        
        for ( int i = 0; i < 52; i++ ) {
            
            Node node;
            
            if ( i % 2 == 0 ) {
                
                node = new Node( ( char )( 'A' + j++ ) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -