An example of the principle of Java EJB encryption and decryption _php tips

Source: Internet
Author: User
Tags gettext stringbuffer
An example of the principle of encryption and decryption

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 (This) (new Lockunlock_jbutton1_actionadapter);
Jbutton2.setbounds (New Rectangle (218, 237, 131, 27));
Jbutton2.settext ("Exercise 4");
Jbutton2.addactionlistener (This) (new Lockunlock_jbutton2_actionadapter);
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);
/* is not a return function (N-1);
But N*function (N-1);
}
}
-----------a recursive method for the whole arrangement of a string-----------------------
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;
/* No return in If? */
}

------------------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);
/* method. parseint is converted to int type
And not. 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);
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.