jsp頁面調用applet實現人民幣的大小寫轉換 (二)

來源:互聯網
上載者:User
js|大小寫|人民幣|頁面|轉換

附錄

1.applet代碼:

 

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="輸入錯誤:"+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="輸入錯誤:"+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;

    }

  }

}

2.java包,歡迎索取lqhboy@163.com




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.