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

📄 systempanel.java

📁 非常有用的加密解密程序
💻 JAVA
字号:
package ss.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import ss.logic.Pri_Encrypter;

public class SystemPanel extends JPanel implements ActionListener{
	
	private JPanel fisrtTop = new JPanel();
	private JPanel secondTop = new JPanel();
	private JPanel secondUpperTop = new JPanel();
	private JPanel secondLowerTop = new JPanel();
	private JPanel bottom = new JPanel();
	private JPanel firstBottom = new JPanel();
	private JPanel secondBottom = new JPanel();
	private JPanel thirdBottom = new JPanel();
	private JPanel EncyptMethodPlace = new JPanel();
	private JPanel EncyptAlgoPlace = new JPanel();
	private JPanel ptPanel = new JPanel();
	private JPanel ctPanel = new JPanel();
	private JPanel encryptButtonPanel = new JPanel();
	private JPanel decryptButtonPanel = new JPanel();
	private JPanel secondLowerTopPanel = new JPanel();
	
	private ButtonGroup encryptMethodGroup = new ButtonGroup();
	private JRadioButton priEncry = new JRadioButton("Private Encrypt", true);
	private JRadioButton pubEncry = new JRadioButton("Public Encypt", false);
	
	private ButtonGroup algorithmGroup = new ButtonGroup();
	private JRadioButton algorithm1 = new JRadioButton("Algorithm1", true);
	private JRadioButton algorithm2 = new JRadioButton("Algorithm2", false);
	
	private JButton encryptButton = GUIFactory.getFactory().creatButtonEncrypt();
	private JButton decryptButton = GUIFactory.getFactory().creatButtonDecrypt();
	
	private JLabel blank1 = new JLabel();
	private JLabel blank2 = new JLabel();
	
	private JTextField ctField = GUIFactory.getFactory().creatTextField();
	private JTextField ptField = GUIFactory.getFactory().creatTextField();;
	
	private String pt, ct;
	
	public SystemPanel(){
		encryptMethodGroup.add(priEncry);
		encryptMethodGroup.add(pubEncry);
		
		algorithmGroup.add(algorithm1);
		algorithmGroup.add(algorithm2);
		
		ptPanel.setLayout(new BorderLayout());
		ptPanel.add(GUIFactory.getFactory().getOLabel(), BorderLayout.WEST);
		ptPanel.add(ptField, BorderLayout.CENTER);
		
		encryptButtonPanel.setLayout(new BorderLayout());
		encryptButtonPanel.add(GUIFactory.getFactory().getOLabel(), BorderLayout.WEST);
		encryptButtonPanel.add(encryptButton, BorderLayout.CENTER);
		
		secondUpperTop.setLayout(new BorderLayout());
		secondUpperTop.add(encryptButtonPanel, BorderLayout.WEST);
		secondUpperTop.add(ptPanel, BorderLayout.CENTER);
		secondUpperTop.add(GUIFactory.getFactory().getOLabel(), BorderLayout.EAST);
		
		
		ctPanel.setLayout(new BorderLayout());
		ctPanel.add(GUIFactory.getFactory().getOLabel(), BorderLayout.WEST);
		ctPanel.add(ctField, BorderLayout.CENTER);
		
		decryptButtonPanel.setLayout(new BorderLayout());
		decryptButtonPanel.add(GUIFactory.getFactory().getOLabel(), BorderLayout.WEST);
		decryptButtonPanel.add(decryptButton, BorderLayout.CENTER);
		
		secondLowerTopPanel.setLayout(new BorderLayout());
		secondLowerTopPanel.add(GUIFactory.getFactory().getOLabel(), BorderLayout.NORTH);
		secondLowerTopPanel.add(secondLowerTop, BorderLayout.CENTER);
		
		secondLowerTop.setLayout(new BorderLayout());
		secondLowerTop.add(decryptButtonPanel, BorderLayout.WEST);
		secondLowerTop.add(ctPanel, BorderLayout.CENTER);
		secondLowerTop.add(GUIFactory.getFactory().getOLabel(), BorderLayout.EAST);
		secondTop.setLayout(new BorderLayout());
		secondTop.add(secondUpperTop, BorderLayout.NORTH);
		secondTop.add(secondLowerTopPanel, BorderLayout.CENTER);
		
		EncyptMethodPlace.setLayout(new BorderLayout());
		EncyptMethodPlace.add(priEncry, BorderLayout.WEST);
		EncyptMethodPlace.add(pubEncry, BorderLayout.CENTER);
		
		firstBottom.setLayout(new BorderLayout());
		blank1.setText("        EncypWay      ");
		firstBottom.add(blank1, BorderLayout.WEST);
		firstBottom.add(EncyptMethodPlace, BorderLayout.CENTER);
		
		EncyptAlgoPlace.setLayout(new BorderLayout());
		EncyptAlgoPlace.add(algorithm1, BorderLayout.WEST);
		EncyptAlgoPlace.add(algorithm2, BorderLayout.CENTER);
		
		secondBottom.setLayout(new BorderLayout());
		blank2.setText("        Algorithm       ");
		secondBottom.add(blank2, BorderLayout.WEST);
		secondBottom.add(EncyptAlgoPlace, BorderLayout.CENTER);
		
		bottom.setLayout(new BorderLayout());
		bottom.add(firstBottom, BorderLayout.NORTH);
		bottom.add(secondBottom, BorderLayout.CENTER);
		bottom.add(thirdBottom, BorderLayout.SOUTH);
		
		this.setLayout(new BorderLayout());
		this.add(fisrtTop, BorderLayout.NORTH);
		this.add(secondTop, BorderLayout.CENTER);
		this.add(bottom, BorderLayout.SOUTH);
		
		encryptButton.addActionListener(this);
		decryptButton.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e){
		pt = ptField.getText();
		if(e.getSource() == encryptButton){
			try {
				priEncrypter.encrypt(pt);
				ctField.setText(priEncrypter.getRealCipherText());
				ptField.setText("");
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}
		
		else if(e.getSource() == decryptButton){
			try {
				priEncrypter.decrypt(ctField.getText());
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			ptField.setText(priEncrypter.getNewPlainTextStr());
		}
		
		
	}
	
	private Pri_Encrypter priEncrypter = new Pri_Encrypter();

}

⌨️ 快捷键说明

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