My J2ME Programming Exercise (5) - ImageItem

xiaoxiao2021-03-05  25

/ * ImageItemlet.java * * CREATED ON April 17, 2005, 8:56 pm * /

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); Aspace = 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!"); Aspaceer.setlayout (item.Layout _Expand);

// The Profram Will Connect to www.163.com and disclay 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 commandion (Command C, Item I) {if (c == ConnectCommand) {Adisplay.SetCurrent (Analert, Afe);}} This program is relatively new place to use the newly added Item class in MIDP2.0 and the Spacer class. The use of appearance mode has been introduced in StringItem.

Public Spacer (INT MinWidth, Int MinHeight), Spacer class is set to item.Layout_expand in this program, which is filled with the remaining blank section. In this way, you can see that the two imageitem objects are located on both ends and layout.

转载请注明原文地址:https://www.9cbs.com/read-34684.html

New Post(0)