首页 跟我学J2ME手机应用开发——高级界面中的基本组件开发技术

跟我学J2ME手机应用开发——高级界面中的基本组件开发技术

举报
开通vip

跟我学J2ME手机应用开发——高级界面中的基本组件开发技术跟我学J2ME手机应用开发——高级界面中的基本组件开发技术 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 1.1 跟我学J2ME手机应用开发——高级界面中的基本组件开发技术 1.1.1 基本组件应用实例 1、Ticker和TextField类 (1)Ticker类是一个类似跑马灯似的类(滚动字幕,滚动消息栏) 所有的Displayable子类都可以加入Ticker组件,只需要利用定义在Displayable类中的setTicker()方法设定或者用getTicker()方法取出窗口内的Tick...

跟我学J2ME手机应用开发——高级界面中的基本组件开发技术
跟我学J2ME手机应用开发——高级界面中的基本组件开发技术 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 1.1 跟我学J2ME手机应用开发——高级界面中的基本组件开发技术 1.1.1 基本组件应用实例 1、Ticker和TextField类 (1)Ticker类是一个类似跑马灯似的类(滚动字幕,滚动消息栏) 所有的Displayable子类都可以加入Ticker组件,只需要利用定义在Displayable类中的setTicker()方法设定或者用getTicker()方法取出窗口内的Ticker对象。Ticker类本身只有一个setString()的方法,用来设定所显示的内容。 (2)TextField为文字输入框,可以输入一行文字信息 TextField类的构造函数,第一个参数是文本域的名称,第二个参数是缺省值,第三个参数是长度,第四个参数是文本域的类型,可选的值有:TextField.PASSWORD、TextField.EMAILADDR、TextField.PHONENUMBER、TextField.URL、TextField. NUMERIC等。 构造好TextField对象之后,调用Form的append()方法将它添加到Form对象的子项目中(mainForm.append(tickerStringInputField);)。TextField类中的常用方法有:insert、delete、setString、getString、getMaxSize、setMaxSize、size等。 package com.px1987.midpgui; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.TextField; import javax.microedition.lcdui.Ticker; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class TickerDemo extends MIDlet implements CommandListener { 1 杨教授工作室,版权所有,盗版必究, 1/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 private Form mainForm= null; private Display displayControl=null; private Command startMenuItem,stopMenuItem; private TextField tickerStringInputField; public TickerDemo() { super(); displayControl=Display.getDisplay(this); mainForm= new Form ("跑马灯Ticker和TextField类示例"); displayControl.setCurrent(mainForm); startMenuItem=new Command("开始",Command.OK,1); stopMenuItem=new Command("停止",Command.STOP,1); mainForm.addCommand(startMenuItem); mainForm.addCommand(stopMenuItem); tickerStringInputField = new TextField("输入跑马灯的文字", null, 25, TextField.ANY); mainForm.append(tickerStringInputField); } public void commandAction(Command oneCommand, Displayable oneDisplayable){ if( oneCommand==startMenuItem){ Ticker oneTicker = new Ticker(tickerStringInputField.getString()); mainForm.setTicker(oneTicker); } else if(oneCommand==stopMenuItem){ mainForm.setTicker(null); } } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { mainForm=null; //手机屏幕将会是一片空白 2 杨教授工作室,版权所有,盗版必究, 2/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 System.gc(); } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { mainForm.setCommandListener(this); //绑定事件 } } 2、StringItem类 (1)主要的功能 StringItem为基本组件对象,它的作用就是在容器对象中显示一条字符串。其中的信息为只读信息,用户不能更改控件中的提示信息,并且可以以按钮或者超级链接形式显示。 (2)构造方法 1) StringItem(String label, String text); 2) StringItem(String label, String text, int appearanceMode) 其中的参数appearanceMode指定控件显示的类型,可以为下面的值之一: 1) Item.PLAIN:默认类型 2) Item.HYPERLINK:超级链接 3 杨教授工作室,版权所有,盗版必究, 3/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 3) Item.BUTTON:图像按钮类型 (3)成员方法 1) getAppearanceMode():取得StringItem所用的外观 2) getFont()/setFont():用来取得/设定字体 3) getText()/setText():用来取得/设定内容 4) getLable()/setLable():存取Label (4)在Form中加入StringItem 可以使用append(Item)方法,form.append(String)等同于调用:form.append(new StringItem(null, String));如果StringItem没有和Command系统菜单项目关联,即使使用不同的外观设定,外观也是相同的。 (5)代码示例 package com.px1987.midpgui; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemCommandListener; import javax.microedition.lcdui.ItemStateListener; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class StringItemDemo extends MIDlet implements CommandListener, ItemStateListener, ItemCommandListener { private Form mainForm= null; private Display displayControl=null; private Command exitMenuItem; 4 杨教授工作室,版权所有,盗版必究, 4/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 private Command startCommand; private Command endCommand; private StringItem onePlainItem; private StringItem oneHyperLinkItem; private StringItem oneButtonItem; public StringItemDemo() { displayControl = Display.getDisplay(this); mainForm = new Form("StringItem功能类示例"); exitMenuItem = new Command("退出", Command.SCREEN, 1); startCommand = new Command("开始", Command.ITEM, 1); endCommand = new Command("结束", Command.ITEM, 1); onePlainItem = new StringItem("普通外观", "普通外观下的文本", Item.PLAIN); onePlainItem.addCommand(startCommand); onePlainItem.addCommand(endCommand); oneHyperLinkItem = new StringItem("超链接外观", "超链接外观下的文本", Item.HYPERLINK); oneButtonItem = new StringItem("按钮外观", "按钮外观下的文本", Item.BUTTON); oneButtonItem.addCommand(startCommand); oneButtonItem.addCommand(endCommand); onePlainItem.setDefaultCommand(new Command("普通外观的默认命令", Command.ITEM, 1)); oneHyperLinkItem.setDefaultCommand(new Command("超链接外观的默认命令",Command.ITEM, 1)); oneButtonItem.setDefaultCommand(new Command("按钮外观的默认命令", Command.ITEM, 1)); onePlainItem.setItemCommandListener(this); oneHyperLinkItem.setItemCommandListener(this); oneButtonItem.setItemCommandListener(this); 5 杨教授工作室,版权所有,盗版必究, 5/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 mainForm.append(onePlainItem); mainForm.append(oneButtonItem); mainForm.insert(1, oneHyperLinkItem); mainForm.addCommand(exitMenuItem); mainForm.setCommandListener(this); } protected void destroyApp(boolean arg0) { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { displayControl.setCurrent(mainForm); } public void commandAction(Command oneCommand, Displayable oneDisplayable){ if (oneCommand == exitMenuItem){ destroyApp(false); notifyDestroyed(); } } public void itemStateChanged(Item it) { } //Form中的Item子类ItemCommandListener对应的事件 public void commandAction(Command oneCommand, Item it) { if (it == onePlainItem) { if (oneCommand == startCommand) { } if (oneCommand == endCommand) { } 6 杨教授工作室,版权所有,盗版必究, 6/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 } if (it == oneHyperLinkItem) { } if (it == oneButtonItem) { if (oneCommand == startCommand) { } if (oneCommand == endCommand) { } } } } 3、DateField类 (1)主要的功能 DateField对象和TextField对象一样同属于基本类型的组件对象,不能够单独显示输出而必须作为容器对象的子项目显示输出。 DateField对象的作用是显示一个日期(显示日历的可视组件),并可以让用户方便地输 7 杨教授工作室,版权所有,盗版必究, 7/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 入日期和时间。 (2)构造方法 1) DateField(String label, int mode) 2) DateField(String label, int mode, TimeZone timeZone) 其中的参数mode指定控件的类型,可以为如下的3种值之一: 1) DateField.DATE:输入日期 2) DateField.TIME:输入时间 3) DateField.DATE_TIME:输入日期和时间 (3)主要的成员方法 1) setInputMode()/getInputMode():设置/取得输入模式 2) setDate()/getDate():设置/取得时间,但Date类需要和Calendar类相互配合使用 (4)代码示例 package com.px1987.midpgui; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.DateField; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemStateListener; import javax.microedition.lcdui.Ticker; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class DateFieldDemo extends MIDlet implements CommandListener, ItemStateListener { private Form mainForm= null; private Display displayControl=null; private Command startMenuItem,stopMenuItem; 8 杨教授工作室,版权所有,盗版必究, 8/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 private DateField tickerStringInputField; public DateFieldDemo() { super(); } public void commandAction(Command oneCommand, Displayable oneDisplayable){ if( oneCommand==startMenuItem){ String tickerText=tickerStringInputField.getLabel()+":"+ tickerStringInputField.getDate().toString(); Ticker oneTicker = new Ticker(tickerText); mainForm.setTicker(oneTicker); } else if(oneCommand==stopMenuItem){ mainForm.setTicker(null); } } public void itemStateChanged(Item item) { if(item==tickerStringInputField){ java.util.Calendar oneCalendar = java.util.Calendar.getInstance(java.util.TimeZone.getDefault()); oneCalendar.setTime(((DateField)item).getDate()); System.out.println("利用DateField实现了对时间的修改和调整~"); } } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { mainForm=null; //手机屏幕将会是一片空白 displayControl=null; System.gc(); } 9 杨教授工作室,版权所有,盗版必究, 9/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { if(displayControl==null){ displayControl=Display.getDisplay(this); mainForm= new Form ("跑马灯Ticker和TextField类示例"); displayControl.setCurrent(mainForm); startMenuItem=new Command("开始",Command.OK,1); stopMenuItem=new Command("停止",Command.STOP,1); mainForm.addCommand(startMenuItem); mainForm.addCommand(stopMenuItem); java.util.Date now = new java.util.Date(); tickerStringInputField = new DateField("当前时间是:", DateField.DATE_TIME); tickerStringInputField.setDate(now); mainForm.append(tickerStringInputField); mainForm.setCommandListener(this); //绑定事件 mainForm.setItemStateListener(this); //绑定事件 } } } (5)测试结果 10 杨教授工作室,版权所有,盗版必究, 10/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 (6)与时间有关的API , System类 long time = System. currentTimeMillis(); 使用该方法可以获得当前时间。 , Date类 Date date = new Date(); 获得当前时间,使用对象的形式来进行 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 达。 , Calendar类 Calendar是时间处理中最常用也是功能最强大的类,可以用它来获得某个时间的日期、星期几等信息。下面的代码是获得日期: Calendar calendar = Calendar. getInstance(); „„ 11 杨教授工作室,版权所有,盗版必究, 11/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 int day = calendar.get(Calendar. DATE) ; 但Calendar中表示月份的数字和实际相差1,即1月用数字0表示,2月用数字1表示,„„12月用数字11表示。 (7)将System类获得的时间转换为Date对象 Date date = new Date(System. currentTimeMillis()); (8)将Date类型的对象转换为Calendar类型的对象 Calendar calendar = Calendar. getInstance(); Date date = new Date(); calendar.setTime(date); 4、ImageItem图形显示控件 (1)主要的功能 在MIDP2.0中,增加了将图片作为按钮或者超级链接的功能,从而可以把图像作为Form的一个控件显示于屏幕。 (2)构造方法——ImageItem(标题,图像,布局,代替文字,类型) 1) ImageItem(String label, Image img, int layout, String altText) 2) ImageItem(String label, Image img, int layout, String altText, int appearanceMode) 其中的参数label代表控件标题,而参数layout代表控件的布局参数,参数altText表示如果不能够显示图片或图片不存在,则使用一个字符串替代图片的显示;最后的参数appearanceMode指定控件显示的类型,可以取如下值之一: 1) Item.PLAIN:默认类型 2) Item.HYPERLINK:超级链接 3) Item.BUTTON:按钮类型 (3)主要的成员方法 setLayout()/getLayout():设置/获取布局 setImage()/getImage():设置/获取ImageItem中的Image图像 setAltText()/getAltText():设置/获取取代文字 getAppearanceMode():取得外观 (4)PNG图像文件 12 杨教授工作室,版权所有,盗版必究, 12/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 流式网络图形格式(Portable Network Graphic Format,PNG)名称来源于非官方的“PNG's Not GIF”,它是一种位图文件(Bitmap File)存储格式,读成“ping”。提出PNG图像文件存储格式的主要目的是试图替代GIF和TIFF文件格式,同时增加一些GIF文件格式所不具备的特性。 PNG用来存储灰度图像时,灰度图像的深度可多到16位,存储彩色图像时,彩色图像的深度可多到48位,并且还可存储多到16位的α通道数据。PNG使用从LZ77派生的无损数据压缩算法。 5、Spacer组件 (1)主要的功能 用来在Form中加入一些空白间隔,但不能与用户进行交互(因为不能使用Command)。Spacer即空白,不能与用户交互,可以设置大小,是MIDP2.0新增的一个控件,其作用是调整Form界面中所包含Item的布局,例如在两个Item之间可以插入一个Spacer来使界面布局看起来更美观。 (2)构造方法 Spacer(int minWidth, int minHeight) (3)代码示例 package com.px1987.midpgui; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.Spacer; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class SpacerDemo extends MIDlet implements CommandListener{ 13 杨教授工作室,版权所有,盗版必究, 13/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 private Form mainForm= null; private Display displayControl=null; private StringItem oneStrItem; private StringItem twoStrItem; public SpacerDemo() { super(); displayControl=Display.getDisplay(this); mainForm= new Form ("空白间隔Spacer类示例"); displayControl.setCurrent(mainForm); oneStrItem=new StringItem(null,"测试用的第一个字符串",Item.PLAIN); twoStrItem=new StringItem(null,"测试用的第二个字符串",Item.PLAIN); mainForm.append(oneStrItem); mainForm.append(new Spacer(100,20)); mainForm.append(twoStrItem); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { mainForm=null; //手机屏幕将会是一片空白 System.gc(); } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { mainForm.setCommandListener(this); //绑定事 } public void commandAction(Command oneCommand, Displayable oneDisplayable){ } } (4)执行后的结果图示 14 杨教授工作室,版权所有,盗版必究, 14/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 (5)没有应用Spacer组件时 也就是将“mainForm.append(new Spacer(100,20));”语句删除掉后,再执行的结果如下 6、ChoiceGroup 1)主要的功能 ( ChoiceGroup的功能与List相近,并同List一样也实现了Choice接口,但它为Item控件。 (2)构造方法 1) ChoiceGroup(String label, int choiceType); 2) ChoiceGroup(String label, int choiceType, String[] stringElements, Image[] imageElements) 其中的参数choiceType指定控件的显示类型,可以为下面的3种之一: 1) Choice.EXCLUSIVE(单选) 2) Choice.MULTIPLE(多选) 3) Choice.POPUP(弹出式菜单) 但在ChoiceGroup中无法使用Choice.IMPLICIT类型,而ChoiceGroup与List的最大不同在于,ChoiceGroup必须在Form中才有用,因为ChoiceGroup为基本组件而List为容器组件。 ChoiceGroup可通过getSelectedFlags返回选择框的选择值的数组,按选项的索引值顺序排列。 (3)代码示例 package com.px1987.midpgui; 15 杨教授工作室,版权所有,盗版必究, 15/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 import java.io.IOException; import java.io.InputStream; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.ChoiceGroup; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.ItemStateListener; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class ChoiceGroupDemo extends MIDlet implements CommandListener,ItemStateListener{ private Display displayControl=null; private Form mainForm= null; private Command exitMenuItem,okMenuItem; private ChoiceGroup oneChoiceGroup; public ChoiceGroupDemo() { super(); displayControl=Display.getDisplay(this); mainForm= new Form ("选择组件ChoiceGroup类示例"); displayControl.setCurrent(mainForm); exitMenuItem=new Command("退出",Command.EXIT,1); okMenuItem=new Command("确认",Command.OK,1); mainForm.addCommand(exitMenuItem); mainForm.addCommand(okMenuItem); 16 杨教授工作室,版权所有,盗版必究, 16/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 InputStream oneInputStream = getClass().getResourceAsStream("/iconImage/starIcon.png"); Image oneImageIcon=null; try { oneImageIcon=Image.createImage(oneInputStream); } catch (IOException e) { e.printStackTrace(); } oneChoiceGroup= new ChoiceGroup("请选择你的账户类型", Choice.EXCLUSIVE); oneChoiceGroup.append("活期",oneImageIcon); //第2个参数代表图像 oneChoiceGroup.append("定期",oneImageIcon); oneChoiceGroup.append("银联卡",oneImageIcon); oneChoiceGroup.append("国债",oneImageIcon); mainForm.append(oneChoiceGroup); } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { mainForm=null; //手机屏幕将会是一片空白 System.gc(); } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { mainForm.setCommandListener(this); //绑定事件 mainForm.setItemStateListener(this); } public void commandAction(Command oneCommand, Displayable oneDisplayable){ } 17 杨教授工作室,版权所有,盗版必究, 17/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 public void itemStateChanged(Item oneItem) { if(oneItem==oneChoiceGroup){ String accountType=oneChoiceGroup.getString(oneChoiceGroup.getSelectedIndex()); System.out.println("账户类型为:"+accountType); } } } 在事件响应方法itemStateChanged()中利用下面的代码可以获得选中的某个选项: String accountType=oneChoiceGroup.getString(oneChoiceGroup.getSelectedIndex()); 其中的oneChoiceGroup.getSelectedIndex()取得选中的项目序列号,然后利用oneChoiceGroup.getString()方法获得对应的文字内容。 (4)执行的结果 (5)事件响应方法内的结果 7、Gauge(英音:[geid?]美音:[ged?],大小,程度;范围;容量) (1)主要的功能 用作进度条使用。 (2)构造方法 Gauge(String label, boolean interactive, int maxValue, int initialValue); 其中的参数interactive指定控件的类型,可以为下面的值: 1) interactive设为true,代表交互类型,可以通过手机键盘控制进度条进度; 18 杨教授工作室,版权所有,盗版必究, 18/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 2) interactive设为false,代表非交互类型,只能通过程序控制进度条。 参数maxValue指定控件最大数值参数,initialValue参数指明初始数值。 (3)主要的成员方法 setMaxValue()/getMaxValue():设定/取得允许的最大值 setValue()/getValue():设定/取得初始值 isInteractive():判断Gauge是否可与用户交互 另外,在系统中还定义了一种无范围的Gauge。但要求此时的Gauge属于非交互类型(也就是要求将第二个参数设置为false),而第三个参数传入Gauge.INDEFINITE就可以产生没有范围的Gauge。此时,第四个参数只能取如下的四种值之一: 1) Gauge.CONTINUOUS_IDLE 2) Gauge.CONTINUOUS_RUNNING 3) Gauge.INCREMENTAL_IDLE 4) Gauge.INCREMENTAL_UPDATING 8、CustomItem应用示例 它是一个自定义的ITEM,但必须要实现CustomItem类中的所有抽象方法才能实例化,并支持ItemStateListener接口。CustomItem子类的对象实例可以接受键盘和触笔输入,而getPrefContentWidth方法获得最佳内容宽度等。 (1)CustomItemDemoMIDlet类 package com.px1987.midpgui; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class CustomItemDemoMIDlet extends MIDlet implements CommandListener{ public CustomItemDemoMIDlet() { 19 杨教授工作室,版权所有,盗版必究, 19/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Form form = new Form("CustomItem应用示例"); form.append(new CustomItemDemo("图像按钮")); Command c = new Command("退出", Command.EXIT, 0); form.addCommand(c); form.setCommandListener(this); Display.getDisplay(this).setCurrent(form); } public void commandAction(Command oneCommand, Displayable oneDisplayable) { if (oneCommand.getCommandType() == Command.EXIT) notifyDestroyed(); } } (2)CustomItemDemo类 package com.px1987.midpgui; import javax.microedition.lcdui.CustomItem; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; public class CustomItemDemo extends CustomItem { private Image image; private String label; private Font font; 20 杨教授工作室,版权所有,盗版必究, 20/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 public CustomItemDemo(String label) { super(label); this.label=label; image=Image.createImage(50,30); font=Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_SMALL); Graphics graphics=image.getGraphics(); graphics.setColor(255,0,0); graphics.fillRect(0, 0, 50, 30); graphics.setColor(0,255,0); graphics.setFont(font); graphics.drawString(label,0, 0, Graphics.LEFT|Graphics.TOP); } /* 重写其中的5个抽象方法 */ protected int getMinContentWidth() { return font.stringWidth(label); } protected int getMinContentHeight() { return font.getHeight(); } protected int getPrefContentWidth(int PrefWidth) { return font.stringWidth(label)+5; } protected int getPrefContentHeight(int PrefHeight) { return font.getHeight()+5; } protected void paint(Graphics oneGraphics, int width, int height) { /* 21 杨教授工作室,版权所有,盗版必究, 21/22页 杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料 * 控制项目的外观,参数包含项目的宽度和高度 */ if (image!=null){ oneGraphics.drawImage(image,0,0, Graphics.TOP|Graphics.LEFT); } } } 22 杨教授工作室,版权所有,盗版必究, 22/22页
本文档为【跟我学J2ME手机应用开发——高级界面中的基本组件开发技术】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_003124
暂无简介~
格式:doc
大小:201KB
软件:Word
页数:0
分类:互联网
上传时间:2017-09-21
浏览量:11