大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> J2ME学习札记 22-26

J2ME学习札记 22-26

时间: 2021-07-31 作者:daque

(22)-----choicegroup东西 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步调的运转功效如次图所示:(缺) (23)-----gauge东西 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步调的运转功效如次图所示:(缺) (24)-----ticker东西 ticker东西是一个名目典型的东西,它的效率十分于一个震动动静栏,在屏幕的上方表露滚 动的消息。 ticker类的结构因变量仅有一个参数,那即是须要震动表露的动静。 package fancy.test; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class showticker extends midlet implements commandlistener { private display display; private form props; private command exitcommand = new command("exit", command.exit, 1); public showticker() { display = display.getdisplay(this); } public void startapp() { props = new form("hello world"); props.append("hello world!\n"); ticker ticker=new ticker("d??¥ò?ò1 ;ìy′oóê"); props.setticker(ticker); 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; } } showticker.java步调的运转功效如次图所示: 25)----获得文本框的值 在前方的例子中,咱们仍旧演练了怎样结构j2me步调的用户界面。此刻有一个题目,那即是 怎样与用户界递交互呢?亦即怎样获得用户经过用户界面输出的值呢?请看底下的例子。 package fancy.test; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class gettextboxvalues extends midlet implements commandlistener { private display display; private textbox txtbox; private command exitcommand = new command("exit", command.exit, 1); private command getcommand = new command("getvalues", command.ok, 1); public gettextboxvalues() { display = display.getdisplay(this); } public void startapp() { //or : //string str="hello world"; //txtbox = new textbox("text box",str,str.length(),0); //the follow code is wrong: //txtbox = new textbox("text box",str,any number here,0); txtbox = new textbox("text box",null,200,0); txtbox.addcommand(exitcommand); txtbox.addcommand(getcommand); txtbox.setcommandlistener(this); display.setcurrent(txtbox); } public void valuesscreen() { form props=new form("get text box values"); props.append(txtbox.getstring()); props.addcommand(exitcommand); props.setcommandlistener(this); display.setcurrent(props); } public void commandaction(command c, displayable s) { if (c == exitcommand) { destroyapp(false); notifydestroyed(); } if(c==getcommand) { valuesscreen(); } } public void destroyapp(boolean unconditional) { } public void pauseapp() { display.setcurrent(null); txtbox = null; } } 在上头的例子中(gettextboxvalues.java),当咱们往文本框中输出文本,并按下退出按钮,接 着采用getvalues吩咐的功夫,将会挪用valuesscreen()本领。valuesscreen()本领的源代码如次 : public void valuesscreen() { form props=new form("get text box values"); props.append(txtbox.getstring()); props.addcommand(exitcommand); props.setcommandlistener(this); display.setcurrent(props); } valuesscreen()本领的论理是:开始创造一个容器东西form,而后挪用textbox东西的getstr ing()本领,获得文本框中的输出值,追加到容器东西中,结果将此form东西动作屏幕的暂时显 示东西。gettextboxvalues.java的运转功效如底下两图所示: (26)-----date东西 date东西是属于java.util包的,它的效率是归来暂时的功夫。请看底下的代码: package fancy.test; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; public class getdate extends midlet implements commandlistener { private display display; private form props; private date date; private command exitcommand = new command("exit", command.exit, 1); public getdate() { display = display.getdisplay(this); } public void startapp() { props = new form("hello world"); props.append("hello world!\n"); date=new date(); props.append("now time:"+date.gettime()+"\n"); 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; } } getdate.java步调的运转功效如次图所示: ------------------------------------------------------------------------------------网易广州社区java版

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.