|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
/* * imageItemlet.java * * Created on 2005年4月17日, 下午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); 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 will 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); } } } 这个程序的比较新的地方在于使用了midp2.0中新增加的ITEM类的外观模式和SPACER类。其中外观模式的使用在StringItem中已经介绍过了。 public Spacer(int minWidth, int minHeight),SPACER类在本程序中设置为Item.LAYOUT_EXPAND,即填充剩余的空白部分。这样,运行后可以看到两个ImageItem对象分别位于左右两端,布局上好看一些。 返回类别: 教程 上一教程: Jawe工作流建模及Shark工作流引擎的实例说明 下一教程: JAVA编码问题的一些理解 您可以阅读与"我的J2ME编程训练(5)??ImageItem"相关的教程: · 我的J2ME编程联系(3)??Gauge · 我的J2ME编程训练(8)??Canvas3 · 我的J2ME作品-水浒笑传之林冲演义 · 我的J2ME作品-大话神仙 · 我的J2ME作品-兄弟连 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |