When MIDlet is in operation, you can obtain the property values of the attributes in the manifest file or description file through the Midlet.getappproperty () function, which is treated as a string. If we need to do some math, we have to convert the string to a numeric value before we can do it.
To convert a string to a numeric value, you must rely on the Parsexxx () method in the byte, Short, Integer, Long four categories defined in Java.lang, which are all integer types, only the difference in scope, if we intercept the string, When converted to a value that exceeds the range that the form can afford, an exception is created.
Because floating-point numbers are not supported in CLDC 1.0, there is no category for floating-point numbers, only integers. But after CLDC 1.1 to support floating-point numbers, so after CLDC 1.1
New float, Double two categories will begin.
Let's say we have two custom attributes, MyAttr1 and MYATTR2, where the MYATTR1 value is 3, and the MYATTR2 value is 6.
We're going to take two values out, multiply and then output on the screen, and the sample program is as follows:
TransformTest.java
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TransformTest extends MIDlet
{
public TransformTest()
{
}
public void startApp()
{
String attr1 = getAppProperty("MyAttr1");
String attr2 = getAppProperty("MyAttr2");
int attr1val1 = Integer.parseInt(attr1) ;
int attr1val2 = Integer.parseInt(attr2) ;
System.out.println(attr1val1*attr1val2) ;
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
}
Execution results:
18
After taking out the string, we can also use Java.lang.Character to determine whether a character is a number, an uppercase letter, and a lowercase letter. You can also use this category to convert the case of English letters.