📄 200603091545555.html
字号:
<P><BR>// Import of API classes<BR>import javax.microedition.midlet.*;<BR>import javax.microedition.lcdui.*;<BR>import java.util.*;</P>
<P>//A first MIDlet with simple text and a few commands.<BR>public <a href="javascript:if(confirm('http://www.itisedu.com/phrase/200604231359565.html \n\nThis file was not retrieved by Teleport Pro, because it was unavailable, or its retrieval was aborted, or the project was stopped too soon. \n\nDo you want to open it from the server?'))window.location='http://www.itisedu.com/phrase/200604231359565.html'" tppabs="http://www.itisedu.com/phrase/200604231359565.html" target="_new">class</a> PhoneCalendar extends MIDlet<BR> implements CommandListener, ItemStateListener {</P>
<P>//The commands<BR>private Command exitCommand;</P>
<P>//The display for this MIDlet<BR>private Display display;</P>
<P>// Display items e.g Form and DateField<BR>Form displayForm;<BR>DateField date;</P>
<P>public PhoneCalendar() {<BR> display = Display.getDisplay(this);<BR>exitCommand = new Command("Exit", Command.SCREEN, 1);<BR> date = new DateField("Select to date", DateField.DATE);</P>
<P>}</P>
<P>// Start the MIDlet by creating the Form and <BR>// associating the exit command and listener.<BR>public void startApp() {<BR>displayForm = new Form("Quick Calendar");<BR> displayForm.append(date);<BR> displayForm.addCommand(exitCommand);<BR>displayForm.setCommandListener(this);<BR>displayForm.setItemStateListener(this);<BR>display.setCurrent(displayForm);<BR>}</P>
<P>public void itemStateChanged(Item item)<BR>{<BR> // Get the values from changed item<BR>}</P>
<P>// Pause is a no-op when there is no background<BR>// activities or record stores to be closed.<BR>public void pauseApp() { }</P>
<P>// Destroy must cleanup everything not handled <BR>// by the garbage collector.<BR>public void destroyApp (boolean unconditional) { }</P>
<P>// Respond to commands. Here we are only implementing<BR>// the exit command. In the exit command, cleanup and<BR>// notify that the MIDlet has been destroyed.<BR>public void commandAction (<BR>Command c, Displayable s) {<BR>if (c == exitCommand) {<BR>destroyApp(false);<BR> notifyDestroyed();<BR>}<BR>}</P>
<P><BR>}<BR> </P>
<P>如上定义的 PhoneCalendar MIDlet 继承了 ItemListener 和 CommandListener。它使 MIDlet 具备了跟踪屏幕上的条目变化和对用户命令作出响应的功能。由此应用程序创建的用户界面从为电话屏幕定义一个显示并附加上一个 Form 开始。该 Form 充当容器使用,可以保持一些用户界面项。commandAction() 函数在 J2ME 中执行命令处理程序,并且定义某个命令应执行的动作。</P>
<P>部署 J2ME<BR>您可以从 Sun 下载一个仿真器,该仿真器允许您在台式机系统上测试 J2ME 应用程序。如果您宁愿避免所有的图形开销,则您也可以在命令行上部署 J2ME。</P>
<P>在仿真环境中进行部署<BR>在仿真环境中部署和运行 J2ME 应用程序,要涉及到仿真器的安装和配置。J2ME Wireless Toolkit 提供了一个仿真环境,该环境用于在资源受限的设备上对 Java 应用程序进行的开发和部署。这里教您如何自己运行它:</P>
<P>安装 J2ME Wireless Toolkit(请参阅参考资料)。安装程序中将会用必要的说明指导您进行安装。为运行这些示例,请选择独立(standalone)<a href="200603061709535.html" tppabs="http://www.itisedu.com/phrase/200603061709535.html" target="_new">模式</a>。如果您想将它集成到 IDE,请选择集成(integrated)模式。</P>
<P><BR>通过 KToolbar 的用户界面创建一个新工程。指定一个类名。</P>
<P><BR>将第 2 步指定的类名放到 C:\[J2ME Installation directory]\apps\[Project Name]\src 目录。</P>
<P><BR>编译这个工程。</P>
<P><BR>从 J2ME Wireless Toolkit -> Default Device Selection 选择 DefaultGrayPhone 作为缺省设备。</P>
<P><BR>运行这个工程。<BR>该工具箱还提供有一个选项,用于把工程打包成一个 jar 文件和一个 jad 文件。双击 jad 文件将会部署 jar 文件所指定的应用程序。</P>
<P>在命令行上进行部署<BR>这里也有一些可用的命令行选项。</P>
<P>1. 创建类文件:</P>
<P><BR>C:\J2ME\apps\PhoneCalendar><BR> javac _ tmpclasses _ootclasspath <BR>C:\J2ME\lib\midpapi.zip -classpath tmpclasses;<BR>classes src\*.java</P>
<P>2. 创建清单文件 manifest.mf:</P>
<P><BR>MIDlet-1: PhoneCalendar,<BR>PhoneCalendar.png,<BR>PhoneCalendar<BR>MIDlet-Name: Phone Calendar<BR>MIDlet-Vendor: Sun Microsystems<BR>MIDlet-Version: 1.0<BR>MicroEdition-Configuration: CLDC-1.0<BR>MicroEdition-Profile: MIDP-1.0</P>
<P>3. 创建 jar 文件:</P>
<P><BR>C:\J2ME\apps\PhoneCalendar>jar cfm .\bin\<BR>PhoneCalendar.jar <BR>manifest.mf -C classes . _ res .<BR> </P>
<P>4. 创建 jad 文件:</P>
<P><BR>MIDlet-1: PhoneCalendar, <BR>PhoneCalendar.png, <BR>PhoneCalendar<BR>MIDlet-Jar-Size: 4490<BR>MIDlet-Jar-URL:<BR>F:\J2ME\apps\PhoneCalendar\bin\<BR>PhoneCalendar.jar<BR>MIDlet-Name: PhoneCalendar<BR>MIDlet-Vendor: Sun Microsystems<BR>MIDlet-Version: 1.0<BR> </P>
<P>5. 运行 jad 文件:</P>
<P><BR>C:\J2ME\bin> emulator -Xdescriptor:<BR>C:\J2ME\apps\PhoneCalendar<BR>\bin\PhoneCalendar.jad<BR></FONT></P></FONT></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -