分享
 
 
 

加密与解密原理的一个例子

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

package lockunlock;

import Java.awt.*;

import java.awt.event.*;

import java.applet.*;

import javax.swing.*;

import java.util.*;

public class LockUnlock extends JApplet {

private boolean isStandalone = false;

//Get a parameter value

public String getParameter(String key, String def) {

return isStandalone ? System.getProperty(key, def) :

(getParameter(key) != null ? getParameter(key) : def);

}

//ConstrUCt the applet

public LockUnlock() {

}

//Initialize the applet

public void init() {

try {

jbInit();

}

catch(Exception e) {

e.printStackTrace();

}

}

//Component initialization

private void jbInit() throws Exception {

contentPane = (JPanel) this.getContentPane();

jLabel1.setText("String");

jLabel1.setBounds(new Rectangle(35, 36, 57, 21));

contentPane.setLayout(null);

this.setSize(new Dimension(400, 300));

jLabel2.setText("String length");

jLabel2.setBounds(new Rectangle(29, 73, 69, 22));

jTextField1.setText("");

jTextField1.setBounds(new Rectangle(108, 40, 166, 17));

jTextField2.setText("");

jTextField2.setBounds(new Rectangle(107, 72, 56, 21));

jButton1.setBounds(new Rectangle(30, 236, 137, 27));

jButton1.setText("Exercise 3");

jButton1.addActionListener(new LockUnlock_jButton1_actionAdapter(this));

jButton2.setBounds(new Rectangle(218, 237, 131, 27));

jButton2.setText("Exercise 4");

jButton2.addActionListener(new LockUnlock_jButton2_actionAdapter(this));

jTextField3.setText("");

jTextField3.setBounds(new Rectangle(106, 105, 58, 21));

jLabel3.setText("MoShu");

jLabel3.setBounds(new Rectangle(36, 106, 86, 18));

contentPane.add(jLabel1, null);

contentPane.add(jButton2, null);

contentPane.add(jButton1, null);

contentPane.add(jLabel3, null);

contentPane.add(jTextField2, null);

contentPane.add(jLabel2, null);

contentPane.add(jTextField3, null);

contentPane.add(jTextField1, null);

}

//Get Applet information

public String getAppletInfo() {

return "Applet Information";

}

//Get parameter info

public String[][] getParameterInfo() {

return null;

}

//Main method

public static void main(String[] args) {

LockUnlock applet = new LockUnlock();

applet.isStandalone = true;

JFrame frame = new JFrame();

//EXIT_ON_CLOSE == 3

frame.setDefaultCloseOperation(3);

frame.setTitle("Applet Frame");

frame.getContentPane().add(applet, BorderLayout.CENTER);

applet.init();

applet.start();

frame.setSize(400,320);

Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);

frame.setVisible(true);

}

//static initializer for setting look & feel

static {

try {

//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());

}

catch(Exception e) {

}

}

//Declare DataMember

int index;

//-----------------------------------------------------

JPanel contentPane;

JLabel jLabel1 = new JLabel();

JLabel jLabel2 = new JLabel();

JTextField jTextField2 = new JTextField();

JTextField jTextField1 = new JTextField();

JButton jButton1 = new JButton();

JButton jButton2 = new JButton();

JTextField jTextField3 = new JTextField();

JLabel jLabel3 = new JLabel();

//----------------------N!------------------------------

public int function(int N){

if(N==1)

return 1;

else{

return N*function(N-1);

/*不是RETURN function(N-1);

而是 N*function(N-1);*/

}

}

//-----------用递归法求一个串的全排列-----------------------

public void Arrange(String prefix,String suffix,int[] Array){

String newPrefix,newSuffix;

int numOfChars =suffix.length();

if(numOfChars==1){

Array[index]=Integer.parseInt(prefix+suffix);

index++;

}

else{

for(int i=1; i<=numOfChars;i++){

newSuffix=suffix.substring(1,numOfChars);

newPrefix=prefix+suffix.charAt(0);

Arrange(newPrefix,newSuffix,Array);

suffix=newSuffix+suffix.charAt(0);

}

}

}

//----------Arrange From the Min to the Max------------------

/*public void RankForArrange(int[] Array){

int bottom=Array.length-1 ;

int temp;

for(int i=bottom;i>0;i--){

for(int j=0;j<i;j++){

if(Array[j]>Array[j+1]){

temp =Array[j];

Array[j] =Array[j+1];

Array[j+1]=temp;

}

}

}

}

*/

//-------------------Find the aim number----------------------

public int FindAim(int aim,int[] Array){

boolean isFound=false;

int location=0;

int length=Array.length ;

for(int i=0;i<length;i++){

if(Array[i]==aim){

location=i;

isFound =true;

}

}

if(isFound)

return location;

else

System.out.println("Not Found");

return location;

/*在if里return 不行吗?*/

}

//------------------Creat String-------------------------------

public String CreatString(int length){

StringBuffer BufString=new StringBuffer();

for(int i=1;i<=length;i++){

BufString.append(i) ;

}

return BufString.toString();

}

//-----------OutPut Result--------------------

public void OutPutResult1(){

index = 0; //clear to 0

String AimString, prefix;

AimString = jTextField1.getText();

int Length = AimString.length();

String strLength = String.valueOf(Length);

int Aim = Integer.parseInt(AimString);

/* 方法.parseInt才是转换为int类型

而不是.getInteger*/

int[] EachArrange = new int[this.function(Length)];

jTextField2.setText(strLength);

prefix = ""; //Make an empty String

if (AimString.length() > 2 &&

AimString.length() < 9 && AimString != "") {

Arrange(prefix, AimString, EachArrange);

//RankForArrange(EachArrange);

Arrays.sort(EachArrange);

String result = String.valueOf(FindAim(Aim, EachArrange));

jTextField3.setText(result);

}

else {

System.out.println("Your String is too short");

}

}

//----------Out put result 2---------------------

public void OutPutRestlt2(){

index=0;//Let index come back to 0

String strLength, strMoShu,

AimString, prefix,suffix;

int Length, MoShu,limit;

strLength = jTextField2.getText();

strMoShu = jTextField3.getText();

Length = Integer.parseInt(strLength);

MoShu = Integer.parseInt(strMoShu);

limit = function(Length);

int[] EachArrange = new int[this.function(Length)];

if (Length > 2&&Length<9&&

strLength!=""&&strMoShu!=""

&&MoShu<limit) {

prefix = "";

suffix =CreatString(Length);

Arrange(prefix, suffix, EachArrange);

Arrays.sort(EachArrange);

String strResult=String.valueOf(EachArrange[MoShu]);

jTextField1.setText(strResult);

}

else

System.out.println("Input Ouf MoShu, Try again") ;

}

void jButton1_actionPerformed(ActionEvent e) {

this.OutPutResult1();

}

void jButton2_actionPerformed(ActionEvent e) {

this.OutPutRestlt2();

}

//-----------------------------------------------------------

}

class LockUnlock_jButton1_actionAdapter implements java.awt.event.ActionListener {

LockUnlock adaptee;

LockUnlock_jButton1_actionAdapter(LockUnlock adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton1_actionPerformed(e);

}

}

class LockUnlock_jButton2_actionAdapter implements java.awt.event.ActionListener {

LockUnlock adaptee;

LockUnlock_jButton2_actionAdapter(LockUnlock adaptee) {

this.adaptee = adaptee;

}

public void actionPerformed(ActionEvent e) {

adaptee.jButton2_actionPerformed(e);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有