java EJB 加密与解密原理的一个例子
发布时间:2023-10-02 06:41:16
加密与解密原理的一个例子
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);
}
}
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 下面为大家举一个例子,请按照下面的步骤: (1)从http://home.gbsource.net/xuankong/dll.z
- 码代码时,有时候需要根据比较大小分别赋值:import randomseq = [random.randint(0, 1000) for _
- 起序:本文是在 python 自己的虚拟环境下做的,不是在 Anaconda 下做的。一、安装想要更改 jupyterlab 的默认启动位置
- 首先.还是看效果.实现对文本域textarea中文字字数的限制。然后.米了...看文件.里面写的很清楚了.下面这个是单独的效果..提示用al
- 在将自定义的网络权重加载到网络中时,报错:AttributeError: 'dict' object has no attr
- XPath 的安装以及使用1 . XPath 的介绍刚学过正则表达式,用的正顺手,现在就把正则表达式替换掉,使用 XPath,有人表示这太坑
- 什么是数据库?数据库是存放数据的“仓库”, * 对此形象地描述为“电子化文件柜
- django admin管理工具有很多好用的功能,例如搜索框、筛选器等,编码简单,功能强大。但是常规的时间筛选有一定局限性,只能显示一定时间
- 凡搞WEB开发的人都离不开HTTP(超文本传输协议),而要了解HTTP,除了HTML本身以外,还有一部分不可忽视的就是HTTP消息头。做过S
- 在实际信息系统开发中,经常会用到各种各样的协议,网络协议常用的有http,tcp,udp等,传输数
- 一、BLOB字段BLOB是指二进制大对象也就是英文Binary Large Object的所写,而CLOB是指大字符对象也就是英文Chara
- 创建表书籍模型: 书籍有书名和出版日期,一本书可能会有多个作者,一个作者也可以写多本书,所以作者和书籍的关系就是多对多的关联关系(many-
- 本文总结了asp初学者在学习asp过程中可能会碰到的常见问题,并做了详细的解答。1.如何用Asp判断你的网站的虚拟物理路径 答:使用Mapp
- sys模块sys模块是与python解释器交互的一个接口sys.argv 命令行参数List,第一个元素是程序本身路径sys.
- 刚开始学python,记录下问题。代码如下:#coding:utf-8import re,urllib2def getHTML(url):
- 本文实例为大家分享了python感知机实现的具体代码,供大家参考,具体内容如下一、实现例子李航《统计学方法》p29 例2.1正例:x1=(3
- css3 Animation: @-webkit-keyframes twinkling{ /
- be前言:期末临近,考Python的同学可以练练问题描述:给定一段长度为N的整数序列A,请从中选出一段连续的子序列(可以为0)使得这段的总和
- Web 设计离不开调色板,现成的调色板多不胜数,不管是 Windows 标准色板,还是 Web 标准色板,还是 Pantone 色板,它们虽
- 关于F.normalize计算理解动机最近多次看到该方法出现,于是准备了解一下,搜了后发现原来是所谓的L2 norm计算简介函数定义torc