Many mobile phones are too large to run MIDP applications, and one of the most effective ways to reduce the size of jar files is to reduce unwanted pictures, for example, when the logo images at startup can be replaced with text, and list items can display only text instead of pictures. In order to adapt to different configurations of mobile phones, our code should be more flexible to write. For example, when you load a picture from a jar package:Image image = null;
try {
image = Image.createImage("/logo.png");
}
catch(Exception ioe) {}
if(image==null) {
g.setColor(0);
g.drawString("info", getWidth()/2, getHeight()/2, Graphics.HCENTER|Graphics.BASELINE);
}
else {
g.drawImage(image, getWidth()/2, getHeight()/2, Graphics.HCENTER|Graphics.VCENTER);
}
If the load fails, the program will be displayed in text, so that for the low configuration of the mobile phone, only need to remove the image of the landscaping interface, and then repackage to get a small size jar package can be released, while the application code has not changed.
Similarly, when you load a UI component such as a list:
Image image = null;
try {
image = Image.createImage("/logo.png");
}
catch(Exception ioe) {}
append("label", image);
This allows the image to affect only the appearance of the interface, without affecting the functionality of the application.