J2ME从零开始(学习笔记5)
2009-09-23 17:36
477 查看
★ Form 及其 Item 组件
Form窗体是Screen的一个子类,可以包含图片、只读文本、可编辑文本、进度条、选项组以及自己可以定义的项目,这些都是Item类的子类。也就是说Item子类都可以显示在Form窗体中。
Form窗体也有两个构造函数,和List相似
Form(String title) 创建一个只包含标题的空白Form
Form(String title ,Item [ ] items)创建一个包含标题和Item的Form
Form窗体的体系结构图
1 StringItem
StringItem只是向用户提示一些信息,其内容不能像文本框那样编辑,其功能如同Lable
有两个构造函数:
StringItem(String label , String text)
StringItem(String label , String text, int appearanceMode)
第二个构造函数的第三个参数为外观,分别是PLAIN、HYPERLINK、BUTTON
同样该组件也提供了一些函数,参照API
以下是些示例代码:
Form窗体是Screen的一个子类,可以包含图片、只读文本、可编辑文本、进度条、选项组以及自己可以定义的项目,这些都是Item类的子类。也就是说Item子类都可以显示在Form窗体中。
Form窗体也有两个构造函数,和List相似
Form(String title) 创建一个只包含标题的空白Form
Form(String title ,Item [ ] items)创建一个包含标题和Item的Form
Form窗体的体系结构图
1 StringItem
StringItem只是向用户提示一些信息,其内容不能像文本框那样编辑,其功能如同Lable
有两个构造函数:
StringItem(String label , String text)
StringItem(String label , String text, int appearanceMode)
第二个构造函数的第三个参数为外观,分别是PLAIN、HYPERLINK、BUTTON
同样该组件也提供了一些函数,参照API
以下是些示例代码:
package J2ME001; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemCommandListener; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class StringItemMIDlet extends MIDlet implements ItemCommandListener { private Form form; private StringItem strItem1; private StringItem strItem2; private StringItem strItem3; private final Command cmdItem1=new Command("Plain",Command.ITEM,1); private final Command cmdItem2=new Command("Button",Command.ITEM,1); private final Command cmdItem3=new Command("Hyperlink",Command.ITEM,1); public StringItemMIDlet(){ strItem1=new StringItem("1","Plain",Item.PLAIN); strItem1.addCommand(cmdItem1); strItem1.setItemCommandListener(this); strItem2=new StringItem("2","Button",Item.BUTTON); strItem2.addCommand(cmdItem2); strItem2.setItemCommandListener(this); strItem3=new StringItem("3","Hyperlink",Item.HYPERLINK); strItem3.addCommand(cmdItem3); strItem3.setItemCommandListener(this); form=new Form("StringItem"); form.append(strItem1);//将Item加到Form中 form.append(strItem2); form.append(strItem3); } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { // TODO Auto-generated method stub } protected void pauseApp() { // TODO Auto-generated method stub } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(form); } public void commandAction(Command command, Item item) { if(command.equals(cmdItem1)){ System.out.println("Plain"); }else if(command.equals(cmdItem2)){ System.out.println("Button"); }else if(command.equals(cmdItem3)){ System.out.println("Hyperlink"); } } }
相关文章推荐
- J2ME从零开始(学习笔记4)
- J2ME从零开始(学习笔记9)
- J2ME从零开始(学习笔记10)
- J2ME从零开始(学习笔记2)
- J2ME从零开始(学习笔记6)
- J2ME从零开始(学习笔记7)
- J2ME从零开始(学习笔记8)
- J2ME从零开始(学习笔记3)
- J2ME学习笔记(七)
- C\C++ 程序员从零开始学习Android - 个人学习笔记(十) - java基础 - 多线程(待续)
- j2me网络开发学习笔记2
- ★(转)J2ME学习笔记(七)
- 学习笔记 从零开始学单片机(9) 串口通信
- C\C++ 程序员从零开始学习Android - 个人学习笔记(八) - java基础 - 继承、抽象类、接口、内部类(待续)
- J2ME 学习笔记1
- AJAX学习笔记--从零开始
- 第二章、Objective-C中的@property、@synthesize和dynamic的用法(iOS学习笔记,从零开始)
- java 从零开始,学习笔记之基础入门<集合>(十六)
- 学习笔记 从零开始学单片机(1) 建立实验环境
- J2ME学习笔记(8)