J2ME MIDP个人所得税计算小应用【附源码】

基于宝蓝JBUILDER所提供的MIDP编程框架使开发J2ME应用变成一件所见即所得的简单事情:(本文所实现的MIDP应用直接使用了浮点数运算,必须于支持CLDC 1.1的环境下运行。对于使用CLDC 1.0实现浮点数运算的类库,请与作者公司联系【北京讯岚 TEL:010-51833115】,象征性有偿索取)

package jmobile;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class MIDletMain extends MIDlet {
  static MIDletMain instance;
  Displayable1 displayable = new Displayable1();
  Alert alert1;
  public MIDletMain() {
    instance = this;
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  public void startApp() {
    Display.getDisplay(this).setCurrent(this.alert1,displayable);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }
  private void jbInit() throws Exception {
    alert1 = new Alert("");
    alert1.setType(AlertType.INFO);
    alert1.setTimeout(2000);
    alert1.setString("北京讯岚 2004");
    alert1.setTitle("");
    alert1.setImage(Image.createImage("/jmobile/Untitled-1.png"));
  }

}
public class Displayable1 extends Form implements CommandListener {
  ChoiceGroup choiceGroup1;
  TextField textField1;
  Alert alert1;
  public Displayable1() {
    super("QuickLine");
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    // Set up this Displayable to listen to command events
    String[] str = {
        "北京", "上海", "深圳", "除北京、上海和深圳的其他地方"};
    choiceGroup1 = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE, str, null);
    textField1 = new TextField("", "", 15, TextField.ANY);
    alert1 = new Alert("");
    alert1.setType(AlertType.INFO);
    textField1.setLabel("您欲计算的收入");
    textField1.setConstraints(TextField.DECIMAL);
    choiceGroup1.setLabel("选择您所在的城市");
    choiceGroup1.setFitPolicy(Choice.TEXT_WRAP_OFF);
    choiceGroup1.setPreferredSize(145, 20);
    this.setCommandListener(new Displayable1_this_commandAdapter(this));
    setCommandListener(this);
    // add the Exit command
    addCommand(new Command("计算", Command.OK, 1));
    addCommand(new Command("Exit", Command.EXIT, 2));
    this.append(textField1);
    this.append(choiceGroup1);

  }

  public void commandAction(Command command, Displayable displayable) {
    /** @todo Add command handling code */

    if(command.getCommandType()==Command.OK){
      try{
      String str=col(this.textField1.getString());
      this.textField1.setString("");
      this.alert1.setTimeout(Alert.FOREVER);
      this.alert1.setString("您应缴纳个人所得税 "+str+" 元");

     Display.getDisplay(MIDletMain.instance).setCurrent(this.alert1,this);
    }
    catch(Exception e)
    {
      this.textField1.setString("");
    }
    }


    if ((command.getCommandType() == Command.EXIT) || (command.getCommandType() == Command.STOP)) {
      // stop the MIDlet
      MIDletMain.quitApp();

    }
  }

  void this_commandAction(Command command, Displayable displayable) {

  }

  private String col(String input) {
 try{
    float v1=800;


    switch(this.choiceGroup1.getSelectedIndex())
       {
        case 0:
                 v1=1000;
         break;
        case 1:
                 v1=1000;
         break;
        case 2:
                 v1=1600;
         break;
       }


       float v2 = java.lang.Float.valueOf(input).floatValue();
       if (java.lang.Float.isNaN(v2)) {
         return "ERROR";
       }

       float v3 = v2 - v1;
       if (v3 <= 0) {
         v3 = 0;
         return java.lang.Float.toString(v3);

       }
       if (v3 <= 500) {
         return java.lang.Float.toString(v3 * 0.05f);

       }
       if (v3 <= 2000) {
         return java.lang.Float.toString(v3 * 0.1f - 25);

       }
       if (v3 <= 5000) {
         return java.lang.Float.toString(v3 * 0.15f - 125);

       }
       if (v3 <= 20000) {
         return java.lang.Float.toString(v3 * 0.2f - 375);

       }
       if (v3 <= 40000) {
         return java.lang.Float.toString(v3 * 0.25f - 1375);

       }
       if (v3 <= 60000) {
         return java.lang.Float.toString(v3 * 0.3f - 3375);

       }
       if (v3 <= 80000) {
         return java.lang.Float.toString(v3 * 0.35f - 6375);

       }
       if (v3 <= 100000) {
         return java.lang.Float.toString(v3 * 0.4f - 10375);

       }
       return java.lang.Float.toString(v3 * 0.45f - 15375);
     }
    catch(Exception e){
       return "ERROR";

    }

    }

 

  class Displayable1_this_commandAdapter
      implements javax.microedition.lcdui.CommandListener {
    Displayable1 adaptee;

    Displayable1_this_commandAdapter(Displayable1 adaptee) {
      this.adaptee = adaptee;

    }

    public void commandAction(Command command, Displayable displayable) {
      adaptee.this_commandAction(command, displayable);
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
J2ME(Java 2 Platform, Micro Edition)是由Sun Microsystems开发的一种Java平台,专门用于在移动设备上运行应用程序。MIDP(Mobile Information Device Profile)是J2ME的一个子集,它定义了在移动设备上运行的应用程序的规范和功能。而MIDP 2.0则是MIDP的第二个版本。 MIDP 2.0增加了许多新的功能和改进,使得开发者能够创建更强大和多样化的移动应用程序。它提供了一个可扩展的用户界面,包括支持图形、文本和交互控件。此外,MIDP 2.0还引入了支持浏览器和网络协议的API,使开发者可以轻松地在移动设备上进行网上浏览、发送和接收数据。 MIDP 2.0还加强了网络通信的能力,引入了新的网络连接API,如HTTP和Socket连接。这使得开发者能够通过互联网或网络进行数据交换和通信。同时,它还支持存储和管理数据的持久化功能,允许应用程序在重启后保留数据。 除了以上功能,MIDP 2.0还提供了音频和视频支持,使开发者能够创建媒体相关的应用程序。开发者还可以利用MIDP 2.0的游戏API创建游戏应用程序,包括图形、动画和触发事件等功能。 总之,J2ME MIDP 2.0是一种用于移动设备的Java平台和规范,提供了丰富的功能和API,使开发者能够创建各种各样的应用程序,包括用户界面、网络通信、数据存储、音频视频和游戏等。它的出现大大促进了移动应用程序的发展和普及。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值