J2ME Practice: Reduce the size of the jar file by decreasing the picture

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.