<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<!-- | |
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. | |
--> | |
<HTML> | |
<HEAD> | |
<TITLE>“Web 应用程序的 Mobile 客户端”向导:创建客户端服务器应用程序 - NetBeans Java ME 教程</TITLE> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > | |
<link rel="stylesheet" type="text/css" href="../../../netbeans.css"> | |
</HEAD> | |
<BODY> | |
<a name="top"></a> | |
<H1>“Web 应用程序的 Mobile 客户端”向导:创建客户端服务器应用程序 </H1> | |
<p>通过 NetBeans IDE,可以创建通过中间件 Web 应用程序即可连接到 Web 服务的客户端 MIDlet。</p> | |
<P>本教程介绍了如何在设备不支持 Java ME 平台的 <a href="http://jcp.org/en/jsr/summary?id=172">JSR-172 规范</a>时使用“Web 应用程序的 Mobile 客户端”向导创建与 Web 服务的连接。此向导会生成一个用于计算两个数字的 Servlet,它可以连接到 Web 应用程序,该应用程序中包含 Web 服务客户端,以及用于对指定数字求和的方法。</p> | |
<p>如果您对 NetBeans Mobility 或 J2EE 不太熟悉,应先阅读 <A HREF="../../docs/javame/quickstart.html">NetBeans Java ME MIDP 快速入门指南</A>,然后再继续学习本教程。</p> | |
<p><b>目录</b></p> | |
<img src="../../../images_www/articles/70/netbeans-stamp.gif" class="stamp" width="114" height="114" alt="本页上的内容适用于 NetBeans IDE 7.0" title="本页上的内容适用于 NetBeans IDE 7.0" > | |
<ul class="class"> | |
<li><a href="#create-web">创建 Web 项目</a> | |
<ul> | |
<LI><A HREF="#create">设置 Web 应用程序项目</A> | |
</LI> | |
<LI><A HREF="#add">添加业务逻辑</A> | |
</LI> | |
<LI><A HREF="#comp">生成项目</A> | |
</LI> | |
</ul></li> | |
<li><a href="#create-mob">创建 Mobile 项目</a> | |
<ul> | |
<LI><A HREF="#create-prj">创建项目</A> | |
</LI> | |
<LI><A HREF="#add-pkg">在项目中添加包和 Visual MIDlet</A> | |
</LI> | |
<li><A href="#add-component">在项目中添加组件</a></li> | |
<li><A HREF="#add-command">在项目中添加命令</a></li> | |
<li><A HREF="#connect-component">连接组件以创建应用程序流</a></li> | |
<li><A HREF="#wizard">“Web 应用程序的 Java ME 客户端”向导</A></li> | |
<li><A HREF="#wizCode">在 Java ME 客户端中添加源代码</A></li> | |
</ul></li> | |
<LI><A HREF="#deploy">部署 Web 项目</A> | |
</LI> | |
<LI><A HREF="#run">运行 Mobile 项目</A> | |
</LI> | |
<LI><A HREF="#check">检查功能</A> | |
</LI> | |
<li><a href="#see-also">另请参见</a></li> | |
</ul> | |
<p><b>要学习本教程,您需要具备下列软件和资源。</b></p> | |
<table> | |
<tbody> | |
<tr> | |
<th class="tblheader" scope="col">软件或资源</th> | |
<th class="tblheader" scope="col">要求的版本</th> | |
</tr> | |
<tr> | |
<td class="tbltd1"><a href="https://netbeans.org/downloads/index.html">带有 Java ME 的 NetBeans Beans</a></td> | |
<td class="tbltd1">版本 7.0 及更高版本 </td> | |
</tr> | |
<tr> | |
<td class="tbltd1"><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java Development Kit</a> (JDK)</td> | |
<td class="tbltd1">版本 6</td> | |
</tr> | |
<tr> | |
<td class="tbltd1">GlassFish 或 Tomcat</td> | |
<td class="tbltd1">包含在 IDE 的 <b>Java EE</b> 和 <b>All</b> 安装中</td> | |
</tr> | |
</tbody> | |
</table> | |
<!--<a name="sample-app"></a> | |
<H2>Installing and Running the Sample Application</H2> | |
<P>Before we begin you might want to see final result of the tutorial.</P> | |
<p>Placeholder</p> | |
<P>Take the following steps to install the <tt>LoginScreenExample</tt> application:</P> | |
<OL> | |
<LI>Download <A HREF="https://netbeans.org/projects/samples/downloads/download/Samples/Mobile/WebToMobile.zip">WebToMobileExample.zip</A>. This download contains the completed NetBeans Mobility and Web projects.</LI> | |
<LI>Unzip the file.</LI> | |
<LI>In the IDE, choose <tt>File</tt> > <tt>Open Project</tt> and browse to the folder that contains the unzipped files with the <tt>WebToMobileExample</tt> project.</LI> | |
<li>Click Open Project.</li> | |
<LI>The Projects view should look like the following:</li> | |
<p class="align-center"> | |
<IMG SRC="../../../images_www/articles/71/mobility/webtomobile/.png" NAME="graphics1" ALT="Project window with sample projects opened" BORDER=1> </p> | |
<LI>In the Projects window, | |
right-click the project <tt>AAA</tt> node and choose | |
Run Project (or press F6 key).</li> | |
<li>Right-click the | |
project <tt>AAA</tt> node and choose Run Project. As the | |
application runs, an emulator window opens and displays the | |
application running in the default device emulator. </LI> | |
<LI>In the Emulator window, click the button underneath | |
"Launch".<BR>The emulator displays BBB, as shown:</li> <p class="align-center"><IMG SRC="../../../images_www/articles/71/mobility/webtomobile/.png" NAME="graphics3" ALT="placeholder" BORDER=1> </p> | |
</OL> | |
<UL> | |
<LI>Moving the cursor up and down allows you to | |
navigate between the Login and Password fields. | |
</LI> | |
<li>Click on the central button enables the selected text field for editing.</li> | |
<LI>Click the button underneath "Login" to finish. | |
</LI> | |
<LI>If the application connects to the server, you'll | |
see the <code>alert1</code> component displayed on the screen with a "Login | |
Successful" message. | |
</LI> | |
</UL> | |
<p class="align-center"><a href="#top">top</a></p>--> | |
<a name="create-web"></a> | |
<H2>创建 Web 项目</H2> | |
<p>使用“Web 应用程序的 Mobile 客户端”向导之前,必须具有包含 Web 服务客户端的 Web 项目。</p> | |
<P><!--Now that you have seen the AAA in action,--> 让我们 | |
<!--go back to the beginning and--> | |
从头开始为 Java Servlet 创建一个新的 Web 应用程序项目。要在 IDE 中创建 Java Web 应用程序,请执行以下操作:</P> | |
<OL> | |
<LI><A HREF="#create">设置 Web 应用程序项目</A> | |
</LI> | |
<LI><A HREF="#add">添加业务逻辑</A> | |
</LI> | |
<LI><A HREF="#comp">编译项目</A> | |
</LI> | |
</OL> | |
<H3><A NAME="create"></A>设置 Web 应用程序项目</H3> | |
<OL> | |
<LI>选择 "File"(文件)> "New Project"(新建项目)(Ctrl-Shift-N 组合键)。<tt></tt><tt></tt>在 "Categories"(类别)下,选择 "Java Web"。在 "Projects"(项目)下选择 "Web Application"(Web 应用程序),然后单击 "Next"(下一步)。 | |
</LI> | |
<LI>在 "Project Name"(项目名称)字段中输入 <CODE>WebApplication</CODE>。将 "Project Location"(项目位置)指定为计算机上的任意目录。在本教程中,将此目录称为 <tt>NetBeansProjects</tt>。 | |
</LI> | |
<li>(可选)选中 "Use Dedicated Folder for Storing Libraries"(使用专用文件夹存储库)复选框,并指定库文件夹的位置。</li> | |
<li>取消选中 "Set as Main Project"(设置为主项目)复选框,然后单击 "Next"(下一步)。 </li> | |
<li>在 "Server and Settings"(服务器和设置)面板中,将 "GlassFish Server 3.1" 保留为稍后要将 Mobile 应用程序部署到的服务器,并将 "J2EE 1.4" 保留为要用于应用程序的版本。</li> | |
<li>将 "Set Source Level to 1.4"(将源级别设置为 1.4)保留为选中状态。 | |
<p class="notes"><b>注意:</b>服务器上的上下文路径将变为 <tt>/WebApplication</tt>(基于您在上一步中为项目指定的名称)。</p> | |
</li> | |
<li>单击 "Next"(下一步)。在 "Frameworks"(框架)面板中,单击 "Finish"(完成)以创建项目。<br> | |
IDE 将创建 <tt>NetBeansProjects/WebApplication</tt> 项目文件夹。此项目文件夹包含所有源代码和项目 meta 数据,例如项目的 Ant 生成脚本。WebApplication 项目将会在 IDE 中打开。在主窗口的源代码编辑器中,将打开欢迎页 index.jsp。 </li> | |
</ol> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/projects-window.png" rel="lytebox" | |
title="WebApplication 项目和 index.jsp"> <img src="../../../images_www/articles/71/mobility/webtomobile/projects-window-reduced.png" | |
alt="WebApplication 项目和 index.jsp" border=1></a></p> | |
<H3><A NAME="add"></A>添加业务逻辑</H3> | |
<p>要在 Web 项目中使用公共方法创建 Java 类,以表示应用程序的业务逻辑,请完成以下步骤: </p> | |
<ol> | |
<li>在 "Projects"(项目)窗口中,右键单击 "Source Packages"(源包)节点,然后选择 "New"(新建)> "Java Package"(Java 包)。<tt></tt>在 "Package Name"(包名)文本框中输入 <tt>MyPackage</tt>,然后单击 "Finish"(完成)。</li> | |
<li>右键单击创建的 <tt>MyPackage</tt> 节点,然后选择 "New"(新建)> "Java Class"(Java 类)。在 "Class Name"(类名)文本框中输入 <tt>Calculator</tt>,然后单击 "Finish"(完成)。 </li> | |
<li>在 "Source Editor"(源代码编辑器)窗口中打开的 <tt>Calculator.java</tt> 文件内,插入以下方法: | |
<pre> public int calcSum(int a, int b) { | |
return a + b; | |
} </pre> | |
</li> | |
<li>按 Ctrl+S 组合键以保存所做的编辑。</li> | |
</ol> | |
<H3><A NAME="comp"></A>生成项目</H3> | |
<p>在 "Projects"(项目)窗口中,右键单击 <tt>WebApplication</tt> 项目节点,然后选择 "Build"(生成)(F11)。<br>此时,用于对数字求和的 Web 应用程序就创建好了。</p> | |
<p class="notes"><b>注意:</b>缺省情况下,项目是在启用 "Compile on Save"(在保存时编译)功能的情况下生成的,因此不需要先对代码进行编译。</p> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/calculator.png" rel="lytebox" | |
title="Calculator.java"> <img src="../../../images_www/articles/71/mobility/webtomobile/calculator-reduced.png" | |
alt="Calculator.java" border=1></a></p> | |
<a name="create-mob"></a> | |
<h2>创建 Mobile 项目</h2> | |
<p>通过 IDE 可以创建客户端 MIDlet 以连接到刚才创建的 Web 应用程序,同时为其提供两个数字并显示它们的和。 </p> | |
<p> 要创建 Java ME 客户端应用程序,请执行以下操作:</P> | |
<OL> | |
<LI><A HREF="#create-prj">创建项目</A> | |
</LI> | |
<LI><A HREF="#add-pkg">在项目中添加包和 Visual MIDlet</A> | |
</LI> | |
<LI><A HREF="#add-component">在项目中添加组件</A> | |
</LI> | |
<li><A HREF="#add-command">在项目中添加命令</a></li> | |
<li><A HREF="#connect-component">连接组件以创建应用程序流</a></li> | |
<li><a href="#wizard">“Web 应用程序的 Java ME 客户端”向导</a></li> | |
</ol> | |
<H3><A NAME="create-prj"></A>创建项目</H3> | |
<p>NetBeans IDE 提供一个使您可以快速创建 MIDP 项目的向导。</p> | |
<OL> | |
<LI>选择 "File"(文件)> "New Project"(新建项目)(Ctrl-Shift-N 组合键)。<tt></tt><tt></tt>在 "Categories"(类别)下,选择 "Java ME"。在 "Projects"(项目)下,选择 "Mobile Application"(Mobile 应用程序),然后单击 "Next"(下一步)。 </LI> | |
<LI>在 "Project Name"(项目名称)字段中输入 <tt>MobileApplication</tt>。将Project Location(项目位置)更改为系统中的某个目录。在本教程中,我们将此目录称为 <tt>NetBeansProjects</tt>。</LI> | |
<LI>取消选中 "Create Hello MIDlet"(创建 Hello MIDlet)复选框(如果缺省为选中状态)。单击 "Next"(下一步)。 </LI> | |
<LI>选择 "Java (TM) Platform Micro Edition SDK 3.0" 作为仿真器平台。单击 "Next"(下一步),然后单击 "Finish"(完成)。<br> | |
IDE 将创建 <tt>NetBeansProjects/MobileApplication</tt> 项目文件夹。<br>此项目文件夹包含所有源代码和项目 meta 数据,例如项目的 Ant 脚本。 | |
<p class="align-center"> | |
<IMG SRC="../../../images_www/articles/71/mobility/webtomobile/mobile-prj-created.png" NAME="graphics1" ALT="已创建 MobileApplication 项目" BORDER=1> </p> | |
</LI> | |
</OL> | |
<h3><A NAME="add-pkg"></A>在项目中添加包和 Visual MIDlet</h3> | |
<OL> | |
<LI>在 "Projects"(项目)窗口中选择 <CODE>MobileApplication</CODE> 项目,然后选择 "File"(文件)> "New File"(新建文件)(Ctrl-N 组合键)。<tt></tt><tt></tt>在 "Categories"(类别)下,选择 "MIDP"。在 "File Types"(文件类型)下,选择 "Visual MIDlet"。单击 "Next"(下一步)。</LI> | |
<LI>在 "MIDlet Name"(MIDlet 名称)和 "MIDP Class Name"(MIDP 类名)字段中输入 <CODE>Calculator</CODE>,然后在 "Package"(包)文本字段中键入 <tt>CalculatorPackage</tt>。单击 "Finish"(完成)。<br> | |
应用程序显示在可视 Mobile 设计器的 "Flow"(流)设计窗口中。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/midlet-added.png" rel="lytebox" | |
title="已添加包和 Visual MIDlet"> <img src="../../../images_www/articles/71/mobility/webtomobile/midlet-added-reduced.png" | |
alt="已添加包和 Visual MIDlet" border=1></a></p> | |
</LI> | |
</OL> | |
<h3><A NAME="add-component"></A>在项目中添加组件</h3> | |
<OL> | |
<LI>在 "Flow"(流)视图中,从组件面板的 "Displayables"(可显示项)类别中拖放以下组件: | |
<UL> | |
<LI>Wait Screen(等待屏幕)</LI> | |
<LI>窗体 (x2)</LI> | |
<li>Alert(警报) | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/components-added.png" rel="lytebox" | |
title="已添加组件"> <img src="../../../images_www/articles/71/mobility/webtomobile/components-added-reduced.png" | |
alt="已添加组件" border=1></a></p></li> | |
</UL> </LI> | |
<li>单击 "Screen"(屏幕)以切换至 "Screen"(屏幕)视图,然后在 "Analyzer"(分析器)按钮右侧的下拉列表中选择 <tt>form</tt>。</li> | |
<li>右键单击 <tt>form</tt> 组件,然后从弹出式菜单中选择 "New/Add"(新建/添加)> "Text Field"(文本字段)。<tt></tt><tt></tt></li> | |
<li>重复上面的步骤 3,以便将另一个 "Text Field"(文本字段)添加到窗体中。</li> | |
<li>选择 <tt>textField</tt> 组件,然后在 "Properties"(属性)窗口(位于组件面板的下方)中输入 <tt>A</tt> 作为 "Label"(标签)值。<tt></tt></li> | |
<li>右键单击 <tt>A</tt> 组件,然后从弹出式菜单中选择 "Rename"(重命名)。</li> | |
<li>在 "Rename"(重命名)对话框的 "New Name"(新名称)字段中输入 <tt>fieldA</tt>,然后单击 "OK"(确定)。</li> | |
<li>选择 <tt>textField1</tt> 组件,然后在 "Properties"(属性)窗口中输入 <tt>B</tt> 作为 "Label"(标签)值。<tt></tt></li> | |
<li>右键单击 <tt>B</tt> 组件,然后从弹出式菜单中选择 "Rename"(重命名)。</li> | |
<li>在 "Rename"(重命名)对话框的 "New Name"(新名称)字段中输入 <tt>fieldB</tt>,然后单击 "OK"(确定)。<br> | |
重命名的字段将代表 <tt>calcSum</tt> 方法的参数。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/fields.png" rel="lytebox" | |
title="字段 A 和字段 B"> <img src="../../../images_www/articles/71/mobility/webtomobile/fields-reduced.png" | |
alt="字段 A 和字段 B" border=1></a></p></li> | |
<li>在 "Analyzer"(分析器)按钮右侧的下拉列表中选择 <tt>form1</tt>。</li> | |
<li>右键单击 <tt>form1</tt> 组件,然后从弹出式菜单中选择 "New/Add"(新建/添加)> "Text Field"(文本字段)。<tt></tt><tt></tt></li> | |
<li>选择 <tt>textField</tt> 组件,然后在 "Properties"(属性)窗口中输入 <tt>Result</tt> 作为 "Label"(标签)值。<tt></tt></li> | |
<li>右键单击 <tt>Result</tt> 组件,然后从弹出式菜单中选择 "Rename"(重命名)。</li> | |
<li>在 "Rename"(重命名)对话框的 "New Name"(新名称)字段中输入 <tt>resultField</tt>,然后单击 "OK"(确定)。<br>重命名的字段用于显示 <tt>calcSum</tt> 方法的输出。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/resultfield.png" rel="lytebox" | |
title=""Result"(结果)字段"> <img src="../../../images_www/articles/71/mobility/webtomobile/resultfield-reduced.png" | |
alt=""Result"(结果)字段" border=1></a></p></li> | |
<li>在 "Analyzer"(分析器)按钮右侧的下拉列表中选择 <tt>alert</tt>。</li> | |
<li> 在 "Properties"(属性)窗口中,将 "Title"(标题)属性更改为 <tt>Alert</tt>,并将 "String"(字符串)属性更改为 <tt>Error while getting results from the web application</tt>。<tt></tt><tt></tt><br>如果 Web 应用程序不返回任何结果,则会显示警报。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/alert.png" rel="lytebox" | |
title=""Alert"(警报)字段"> <img src="../../../images_www/articles/71/mobility/webtomobile/alert-reduced.png" | |
alt=""Alert"(警报)字段" border=1></a></p> </li> | |
</ol> | |
<h3><A NAME="add-command"></A>在项目中添加命令</h3> | |
<ol> | |
<li>在 "Screen"(屏幕)视图中,在 "Device Screen"(设备屏幕)内右键单击,然后从弹出式菜单中选择 "New/Add"(新建/添加)> "Exit Command"(退出命令)(如果已选中 <tt>form1</tt>)。<tt></tt><tt></tt> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/second-form.png" rel="lytebox" | |
title="Form1:已添加 exitCommand"> <img src="../../../images_www/articles/71/mobility/webtomobile/second-form-reduced.png" | |
alt="Form1:已添加 exitCommand" border=1></a></p> </li> | |
<li>在 "Screen"(屏幕)视图中,从 "Analyzer"(分析器)按钮右侧的下拉列表中选择 <tt>form</tt>。</li> | |
<li>在 "Device Screen"(设备屏幕)内右键单击,然后从弹出式菜单中选择 "New/Add"(新建/添加)> "Ok Command"(确定命令)。<tt></tt><tt></tt></li> | |
<li>重复上面的步骤 4,以便通过弹出式菜单添加 "Cancel Command"(取消命令)。<tt></tt> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/first-form.png" rel="lytebox" | |
title="窗体:已添加 okCommand 和 cancelCommand"> <img src="../../../images_www/articles/71/mobility/webtomobile/first-form-reduced.png" | |
alt="窗体:已添加 okCommand 和 cancelCommand" border=1></a></p></li> | |
<li>按 Ctrl+S 组合键以保存所做的编辑。</li> | |
</ol> | |
<h3><A NAME="connect-component"></A>连接组件以创建应用程序流</h3> | |
<p>在 "Flow"(流)视图中,单击 "Mobile Device"(移动设备)上的 "Started"(已启动)文本,然后将其拖至 <tt>form</tt> 组件中。<tt></tt>采用相同的方法,按照下图所示连接各个组件。</p> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/app-flow.png" rel="lytebox" | |
title="应用程序流"> <img src="../../../images_www/articles/71/mobility/webtomobile/app-flow-reduced.png" | |
alt="应用程序流" border=1></a></p> | |
<h3><A NAME="wizard"></A>“Web 应用程序的 Java ME 客户端”向导</h3> | |
<p>我们将使用“Web 应用程序的 Java ME 客户端”向导在 Mobile 项目内创建 Mobile 客户端并选择 <tt>calcSum</tt> 方法。</p> | |
<OL> | |
<LI>展开 <tt>MobileApplication</tt> 并右键单击 "Source Packages"(源包),然后选择 "New"(新建)> "Java ME Client to Web Application"(Web 应用程序的 Java ME 客户端)。<tt></tt><tt></tt><tt></tt></LI> | |
<li>在 "Servlet and Client Type"(Servlet 和客户端类型)面板中,选择 MIDlet 与之进行交互的 Web 应用程序的类型:输入 <tt>WebToMobileServlet</tt> 作为 Servlet 名称,并确保选中 "Methods in Web Application"(Web 应用程序中的方法)选项(因为 Mobile 客户端将直接连接到该 Web 应用程序),然后单击 "Next"(下一步)。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/wizard.png" rel="lytebox" | |
title="向导"> <img src="../../../images_www/articles/71/mobility/webtomobile/wizard-reduced.png" | |
alt="向导" border=1></a></p></li> | |
<li>在 "Methods In Web Project"(Web 项目中的方法)面板中,选中 "int calcSum (int a, int b)",然后单击 "Next"(下一步)。<tt></tt></li> | |
<li>在 "Client Options"(客户端选项)面板中,将生成的客户端的名称和包保留原样,并确保选中 "Generate stubs"(生成桩模块)和 "Allow floating point"(允许浮点)选项,然后单击 "Finish"(完成)。<br> | |
此时将在 Java ME 项目下方生成 Java ME 客户端和映射文件。<br> | |
同时,将在 Web 项目下方生成 Servlet 和相关类。 | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/client-generated.png" rel="lytebox" | |
title="已生成 Java ME 客户端"> <img src="../../../images_www/articles/71/mobility/webtomobile/client-generated-reduced.png" | |
alt="已生成 Java ME 客户端" border=1></a></p></li> | |
</ol> | |
<h3><A NAME="wizCode"></A>在 Java ME 客户端中添加源代码</h3> | |
<ol> | |
<li>单击 "Calculator.java" 标签。<tt></tt></li> | |
<li>在 "Screen"(屏幕)视图中,从 "Analyzer"(分析器)按钮右侧的下拉列表中选择 <tt>waitScreen</tt>。</li> | |
<li>右键单击 "Resources"(资源)下方的 "task [SimpleCancellableTask]",然后在弹出式菜单中选择 "Go to Source"(转至源)。<tt></tt></li> | |
<li>在源代码编辑器中,找到 <tt>// write task-execution user code here</tt> 部分并将其替换为以下代码: | |
<pre> WebToMobileClient wc = new WebToMobileClient(); | |
int a = Integer.valueOf(getFieldA().getString()).intValue(); | |
int b = Integer.valueOf(getFieldB().getString()).intValue(); | |
int result = wc.calcSum(a, b); | |
System.out.println(result); | |
getResultField().setString(String.valueOf(result));</pre></li> | |
<li>按 Ctrl+S 组合键以保存所做的编辑。</li> | |
</ol> | |
<a name="deploy"></a><H2>部署 Web 项目</H2> | |
<p>要部署 Web 应用程序,请在 "Projects"(项目)窗口中,右键单击 "WebApplication" 节点,然后从弹出式菜单中选择 "Deploy"(部署)。<tt></tt><br>此时将显示 "Output"(输出)窗口,如下所示:</p> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/web-deploy.png" rel="lytebox" | |
title="已部署 WebApplication"> <img src="../../../images_www/articles/71/mobility/webtomobile/web-deploy-reduced.png" | |
alt="已部署 WebApplication" border=1></a></p> | |
<p class="align-center"><a href="#top">返回页首</a></p> | |
<H2><A NAME="run"></A>运行客户端项目</H2> | |
<p> 要运行 Mobile 客户端应用程序,请选择 "Run"(运行)> "Run Main Project"(运行主项目),或按 F6 键以运行主项目。<tt></tt><tt></tt></p> | |
<p class="notes"><b>注意:</b>在运行客户端应用程序之前,请确保服务器端应用程序已部署且正在运行。</p> | |
<p>当 MobileApplication 运行时,将会打开一个仿真器窗口,显示在缺省设备仿真器中运行的应用程序。<tt></tt></p> | |
<p class="align-center"> | |
<a href="../../../images_www/articles/71/mobility/webtomobile/client-run.png" rel="lytebox" | |
title="仿真器中的客户端应用程序"> <img src="../../../images_www/articles/71/mobility/webtomobile/client-run-reduced.png" | |
alt="仿真器中的客户端应用程序" border=1></a></p> | |
<a name="check"></a><H2>检查功能</H2> | |
<ol> | |
<li>在 "Emulator"(仿真器)窗口中,在 "A" 字段中输入任意数字,并通过单击中心按钮旁的向下箭头键切换至 "B" 字段,然后在 "B" 字段中输入另外一个数字。 | |
<p class="align-center"><img src="../../../images_www/articles/71/mobility/webtomobile/ab.png" | |
alt="设置 "A" 和 "B"" border=1></p></li> | |
<li>单击 "Menu" 下方的按钮,并在弹出式菜单中选择 "OK"(确定),然后单击 "Emulator"(仿真器)上的中心按钮进行确认。<br> | |
在 WebApplication 对您输入的数字进行求和之后,将会在 <tt>form1</tt> 中显示结果。 | |
<p class="align-center"><img src="../../../images_www/articles/71/mobility/webtomobile/abresult.png" | |
alt="已计算结果" border=1></p> | |
<p class="notes"><b>注意:</b>要查看该教程的最终结果,请下载 <A HREF="https://netbeans.org/project_downloads/samples/Samples/Mobile/MobileClientToWebApplicationSample.zip">MobileCientToWebApplicationSample.zip</A>。</p> </li> | |
</ol> | |
<p class="align-center"><a href="#top">返回页首</a></p> | |
<div class="feedback-box"><a href="/about/contact_form.html?to=6&subject=Creating%20a%20Client-Server%20Application">请将您的反馈发送给我们</a><br style="clear:both;" ></div> | |
<br style="clear:both;" > | |
<a name="see-also"></a> | |
<H2>另请参见</H2> | |
<UL> | |
<li><a href="smscomposer.html">可视 Mobile 设计器定制组件:创建 SMS 编写器应用程序</a></li> | |
<li><a href="filebrowser.html">可视 Mobile 设计器定制组件:创建移动设备文件浏览器</a></li> | |
<li><a href="pimbrowser.html">可视 Mobile 设计器定制组件:创建个人信息管理器应用程序</a></li> | |
<li><a href="splashscreen.html">可视 Mobile 设计器定制组件:在 Java ME 应用程序中使用闪屏</a></li> | |
<li><a href="waitscreen.html">可视 Mobile 设计器定制组件:为 Mobile 应用程序创建等待屏幕</a></li> | |
<li><a href="tableitem.html">可视 Mobile 设计器定制组件:在 Java ME 应用程序中使用表项</a></li> | |
<li><a href="http://wiki.netbeans.org/VisualMobileDesignerPalatteReference">参考:可视 Mobile 设计器组件面板指南</a></li> | |
</UL> | |
<p class="align-center"><a href="#top">返回页首</a></p> | |
</BODY> | |
</HTML> |