Based on the MIDP programming framework provided by the Bo-blue JBuilder enables the development J2ME application to become a simple thing you have obtained: (The MIDP application implemented in this article directly uses the floating point calculation, must be run in the environment that supports CLDC 1.1. Using CLDC 1.0 to implement a floating-point calculation class library, please contact the author. [Beijing Xunyi Tel: 010-518333115]
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 ("Beijing Xunyi 2004"); Alert1.SetTitle (""); Alert1.SetImage (Image.createImage ("/ jmobile / usd-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 = {"Beijing", "Shanghai", "Shenzhen", "other places in Beijing, Shanghai and Shenzhen"} Choicegroup1 = new choicegroup ("", null); textfield1 = new textfield (",", 15, textfield.any); Alert1 = new alert (""); alert1.settype (AlertType. INFO); textField1.setLabel ( "You want to calculate income"); textField1.setConstraints (TextField.DECIMAL); choiceGroup1.setLabel ( "select your city"); 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 ("Calculation", 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 ("You should pay personal income tax" Str "yuan");
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.toTString (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.toTString (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 imports javax.microedition.lcdui.commandlistener {Displayable1 Adaptee DISPLAYABLE1 Adaptee
Displayable1_this_commandadapter (Displayable1 Adaptee) {this.adaptee = adaptee
}