mage Cannot be shown"); ImageItem类的构造函数有三个参数,第一个参数的作用是显示一个标签,第二个参数指明图 片的对齐方式,第三个参数的作用是显示图片的tip。 3.利用容器类对象的append()方法将ImageItem对象添加进去。如: props.append(imgItem); 下面我们来看一个比较完整的例子。 package fancy.test;
import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
public class ShowImageItem extends MIDlet implements CommandListener { private Display display; private Form props; private Image img; private ImageItem imgItem; private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public ShowImageItem() { display = Display.getDisplay(this); }
public void startApp() { props = new Form("Hello World"); //props.append("Hello World!\n"); try { img=Image.createImage("/fancy/test/JavaPowered-8.png"); imgItem=new ImageItem("Default Layout", img,ImageItem.LAYOUT_DEFAULT,"Image Cannot be shown"); props.append(imgItem); props.append(new ImageItem("Left Layout", img,ImageItem.LAYOUT_LEFT,"Image Cannot be shown")); props.append(new ImageItem("Center Layout", img,ImageItem.LAYOUT_CENTER,"Image Cannot be shown")); } catch(Exception fe) { //to do nothing }
props.addCommand(exitCommand); props.setCommandListener(this); display.setCurrent(props); }
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } }
public void destroyApp(boolean unconditional) { }
public void pauseApp() { display.setCurrent(null); props = null; }
} ShowImageItem.java程序的运行效果如下图所示:
ChoiceGroup对象 发信站: 北大未名站 (2001年10月20日21:12:23 星期六) , 站内信件
ChoiceGroup也是一个项目类型的对象,它代表一个选择列表,它的作用和List对象类似,不 过后者是一个容器,而前者是一个项目。 我们需要特别注意ChoiceGroup类的构造函数,它有四个参数,第一个参数是标签,第二个参 数是此选择列表的类型,例如多选还是单选。第三个参数是一个字符串数组,代表每个选项的 标签,第四个选项是一个Image类型的数组,代表每个选项前面的小图标。下面是一个比较完整 的例子。 package fancy.test;
import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
public class ShowChoiceGroup extends MIDlet implements CommandListener { private Display display; private Form props; private Image duke; private Image[] imageArray; private ChoiceGroup choice; private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public ShowChoiceGroup() { display = Display.getDisplay(this); }
public void startApp() { props = new Form("Hello World"); //props.append("Hello World!\n"); try { Image duke= Image.createImage("/fancy/test/Icon.png"); imageArray = new Image[]{duke,duke,duke}; String[] stringArray = { "Option A", "Option B", "Option C" }; choice=new ChoiceGroup("choice group", ChoiceGroup.MULTIPLE,stringArray,imageArray); props.append(choice); } catch(Exception fe) { //to do nothing. } props.addCommand(exitCommand); props.setCommandListener(this); display.setCurrent(props); }
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); }
public void destroyApp(boolean unconditional) { }
public void pauseApp() { display.setCurrent(null); props = null; } } ShowChoiceGroup.java程序的运行效果如下图所示:
Gauge对象 发信站: 北大未名站 (2001年10月20日21:13:19 星期六) , 站内信件
Gauge对象是一个项目类型的对象,它的作用是显示一个进度条。请看下面的源代码。Gaug e类的构造函数的后面两个参数分别是进度条的最大值和初始值。 package fancy.test;
import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
public class ShowGauge extends MIDlet implements CommandListener { private Display display; private Form props; private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public ShowGauge() { display = Display.getDisplay(this); }
public void startApp() { props = new Form("Hello World"); //props.append("Hello World!\n"); Gauge gauge=new Gauge("show gauge",true,100,50); props.append(gauge); props.addCommand(exitCommand); props.setCommandListener(this); display.setCurrent(props); }
public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } }
public void destroyApp(boolean unconditional) { }
public void pauseApp() { display.setCurrent(null); props = null; }
} ShowGauge.java程序的运行效果如下图所示: 上一页 [1] [2]
|