My J2ME Programming Exercise (5)--imageitem

Source: Internet
Author: User
Tags exit connect
Programming
* * * Imageitemlet.java * * Created on April 17, 2005, 8:56

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

/** * * @author   administrator * @version  */public class Imageitemlet extends MIDlet Implements commandlistener,itemcommandlistener{        private Form aform;     Private Image sohuimage;    Private image neimage;    Private Imageitem sohuimageitem;    private Imageitem neimageitem;    private Display adisplay;     Private Command exitcommand;    private command connectcommand;    private Spacer aspacer;    Private Alert analert;            Public Imageitemlet () {        aform=new Form ("Imageitemtest");         exitcommand=new Command ("EXIT", command.exit,1);         connectcommand=new Command ("Connect", command.item,2);       &nbsp Aspacer=new spacer (10,2);        analert=new Alert ("Connecting ...", "Connecting To www.163.com ... ",                Null,alerttype.info);        try{             sohuimage=image.createimage ("/sohu.png");             sohuimageitem=new Imageitem (null,sohuimage,imageitem.layout_right,                     "This is sohu!");                          aspacer.setlayout (Item.layout_expand);

The Profram'll connect to www.163.com and display the Alert//when click the Imageitem of 163.png.

            neimage=image.createimage ("/163.png");             neimageitem=new Imageitem (Null,neimage, imageitem.layout_right,                     "This is 163", Item.hyperlink);             Neimageitem.setitemcommandlistener (This);             Neimageitem.setdefaultcommand (Connectcommand);                         Aform.append ( Sohuimageitem);            aForm.append (aSpacer);             aform.append (Neimageitem);             Aform.addcommand (Exitcommand);            Aform.setcommandlistener (this);       }                         catch (Exception e) {             e.printstacktrace ();        }           }    public void STARTAPP () {        adisplay=display.getdisplay (this);         adisplay.setcurrent (aform);   }        public void Pauseapp () {   }        public void Destroyapp (Boolean Unconditional) {   }        public void commandaction (Command C,disPlayable d) {        if (C==exitcommand) {             Destroyapp (False);             notifydestroyed ();       }   }         public void Commandaction (Command c,item i) {        if (c== Connectcommand) {            aDisplay.setCurrent (AnAlert, aform);       }   }       }

A newer aspect of this program is the use of the midp2.0 and spacer classes of the newly added item class in the. The use of the appearance pattern has been introduced in the Stringitem.

Public spacer (int minwidth, int minheight), spacer class in this program is set to Item.layout_expand, that is, fill the remaining white space. In this way, after running, you can see two Imageitem objects located on both sides of the left and right, the layout of some good-looking.


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.