JSP page invoke applet to realize the capitalization conversion of RMB

Source: Internet
Author: User
Tags getcolor include integer lowercase
js| Case | rmb | page | conversion
Implementation method One



Applet Implementation page is rmb.jsp, this page is through the applet to achieve the RMB lowercase conversion to uppercase. This page has three variables that need to be initialized when classes is loaded:

<applet type= "applet" id= "myapplet" codebase = "" Name= "Testapplet"

Align= "Middle" code= "Lqh.rmb.Applicate.Rmb.class"

Width= "560" height= ">"

<param name= "Rgb_back" value= "241|247|251" >

<param name= "Rgb_fore" value= "255|0|0"/>

<param name= "Wigth" value= "560"/>

</applet>

Variable rgb_back is to initialize the background color, modify the secondary variable can make the background color of the applet and its own page style; variable rgb_fore is the color of the initialization font; Wigth to the width of the applet, this variable is guaranteed to display the conversion information in the middle.

This method cannot pass a value to the page trans.jsp and can only be displayed and cannot be copy.



The page code is as follows:



<%@ page contenttype= "text/html;charset=gb2312"%>

<script language=javascript>

function trans () {

Take the value of a variable

var aaa=document.rmb. Rmb_test.value;

Assign a variable to the applet value

Document.myApplet.setRMB (AAA);

Document.myApplet.repaint ();

return true;

}

</SCRIPT>

<body>

<form name= "RMB" >

Enter Amount: <input type= "text" name= "Rmb_test" onkeyup= "Trans ()" ><br>
<%@ include file= ". /rmb.jsp "%>

</form>

</body>




Implementation Method Two



Applet Implementation page is rmb.jsp, this page is through the applet to achieve the RMB lowercase conversion to uppercase. This page does not require a variable initialization, the image that the applet paints is not displayed on the page, and the converted value can be passed to the page variable:

<applet type= "applet" id= "myapplet" codebase = "" Name= "Testapplet"

Align= "Middle" code= "Lqh.rmb.Applicate.Rmb.class"

Width= "0" height= "0" >

</applet>



The page trans.jsp code is as follows:



<%@ page contenttype= "text/html;charset=gb2312"%>

<%@ include file= ". /rmb.jsp "%>

<script language=javascript>

function trans () {

var aaa=document.rmb. Rmb_test.value;

Get the converted Value

var RMB = Document.myApplet.getRMB (AAA);

DOCUMENT.RMB. Rmb_result.value = RMB;

return true;

}

</SCRIPT>

<body>

<form name= "RMB" >

Enter Amount: <input type= "text" name= "Rmb_test" onkeyup= "Trans ()" ><br>

Convert result: <input type= "text" name= "Rmb_result" ><br>

</form>

</body>


Appendix

1. Applet code:



Package lqh.rmb.Applicate;



Import java.awt.*;

Import java.awt.event.*;

Import java.applet.*;

Import lqh.rmb.*;



public class RMB extends Applet {

Private Boolean isstandalone = false;

Private rmbconversion rmb=new rmbconversion ();

Private String var0 = "";

Private String re_rmb= "";

Private String Wigth = "0";

Private String Back_color;

Private String Fore_color;



public string GetParameter (string key, String def) {

Return Isstandalone? System.getproperty (Key, Def):

(GetParameter (key)!= null getparameter (key): Def);

}

public void Paint (Graphics g) {

if (Wigth.equals ("0")) {

Wigth = "560";

}

int i= integer.parseint (wigth);



if (Checknum (var0)) {

if (Var0.endswith (".")) {

Var0 = var0.substring (0,var0.length ()-1);

}

re_rmb= RMB. RMB (VAR0);

}else{

re_rmb= "Input error:" +VAR0;

}

int Middel = (i-re_rmb.length () *12)/2;

This.setbackground (New Color (GetColor (Back_color) [0], GetColor (Back_color) [1], GetColor (Back_color) [2]));

This.setforeground (New Color (GetColor (Fore_color) [0], GetColor (Fore_color) [1], GetColor (Fore_color) [2]));

g.DrawString (re_rmb,middel,20);

}

public void init () {

try {

Back_color = This.getparameter ("Rgb_back", "241|247|251");

}catch (Exception e) {e.printstacktrace ();}

try {

Fore_color = This.getparameter ("Rgb_fore", "255|0|0");

}catch (Exception e) {e.printstacktrace ();}

try {

Wigth = This.getparameter ("wigth", "0");

}catch (Exception e) {e.printstacktrace ();}

try {

Jbinit ();

}catch (Exception e) {e.printstacktrace ();}

}

private void Jbinit () throws Exception {

This.setbackground (New Color (GetColor (Back_color) [0], GetColor (Back_color) [1], GetColor (Back_color) [2]));

}

public void Setrmb (String rmb_temp) {

Var0 = rmb_temp;

}

public string GETRMB (string rmb_temp) {

if (Checknum (rmb_temp)) {

if (Rmb_temp.endswith (".")) {

Rmb_temp = rmb_temp.substring (0,rmb_temp.length ()-1);

}

re_rmb= RMB. RMB (rmb_temp);

}else{

re_rmb= "Input error:" +RMB_TEMP;

}

return RE_RMB;

}

public boolean checknum (String str) {

String numchar= "0123456789.";

Boolean breakboolean = false;

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

if (Numchar.indexof (str.substring (i,i+1)) <0) {

Breakboolean =true;

}

if (Breakboolean) break;

}

if (Breakboolean) {

return false;

}else{

if (Str.startswith (".")) {

return false;

}else{

return true;

}

}

}

Public string[][] GetParameterInfo () {

string[][] pinfo =

{

{"Rgb_back", "String", ""},

{"Rgb_fore", "String", ""},

{"Wigth", "String", ""},

};

return pinfo;

}

Private int[] GetColor (String RGB) {

int[] Rgb_return = new Int[3];

int index =0,nextindex=0,len=0;

while ((Index =rgb.indexof ("|", Nextindex)) >-1) {

Rgb_return[len]=getint (rgb.substring (Nextindex,index));

nextindex=index+1;

len++;

}

Rgb_return[len]=getint (rgb.substring (Nextindex));

return rgb_return;

}

private int getInt (String str) {

try{

return Integer.parseint (str);

}catch (Exception e) {

return 0;

}

}

}





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.