blob: 26fc8d06785b254322a9856f96ccad9d47f81951 [file] [log] [blame]
<!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>
<link rel="stylesheet" type="text/css" href="../../../netbeans.css">
<title>《NetBeans Java ME CDC 开发快速入门指南》</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="SourceCastVersion" content="2.6.2.4.10">
<meta name="keywords" content="NetBeans, IDE, Platform, open source, developer, Java ME, CDC">
<meta name="Alyona Stashkova" content="Alyona.Stashkova@oracle.com">
</head>
<!-- Begin Content Area -->
<body>
<a name="top"></a>
<h1>《NetBeans Java ME CDC 开发快速入门指南》</h1>
<h2>简介</h2>
<p>联网的设备配置 (CDC) 应用程序专门运行在至少有 2 MB 内存的移动设备和嵌入式设备上。与基于 MIDP 的移动电话相比,此配置所支持的 JVM 的功能更加丰富;前者通常只具有极少的内存,并且使用联网的受限设备配置 (CLDC)。本教程将向您说明如何使用 NetBeans IDE 创建 Java Platform, Micro Edition(Java ME 平台)CDC 应用程序。我们将向您演示如何使用三种可用 CDC 配置文件创建在设备仿真器中显示简单窗体的 Java ME CDC 项目。简而言之,本文档的意图旨在帮助您尽可能快速地创建应用程序。 </p>
<p class="notes"><b>注:</b>如果使用的是 NetBeans IDE 7.3,请参阅《<a href="../../73/javame/cdc-quickstart.html">NetBeans 7.3 Java ME CDC 开发快速入门指南</a>》。</p>
<!--<ul>
<li>If you are using NetBeans IDE 6.9, 7.0, 7.1.1, or 7.1.2, refer to the <a href="../../71/javame/cdc-quickstart.html">NetBeans 6.9, 7.0, 7.1.1, or 7.1.2 Java ME CDC Development Quick Start Guide</a>.</li>
<li>If you are using NetBeans IDE 7.2.1, refer to the <a href="../../72/javame/cdc-quickstart.html">NetBeans 7.2.1 Java ME CDC Development Quick Start Guide</a>.</li>
<li>Versions 7.1 and 7.2 of the NetBeans IDE do not support Java ME SDK.</li>
</ul>-->
<h3>目录</h3>
<img alt="此页上的内容适用于 NetBeans IDE 7.4" class="stamp" src="../../../images_www/articles/74/netbeans-stamp.png" title="此页上的内容适用于 NetBeans IDE 7.4">
<ul>
<li><a href="#reqs">要求</a></li>
<li><a href="#platforms">支持的 CDC 仿真器平台</a></li>
<li><a href="#sdkinstall">安装 Oracle Java ME SDK</a></li>
<li><a href="#cdcinstall">安装 Oracle Java ME CDC 平台</a></li>
<li><a href="#plugin">激活 Java ME</a></li>
<li><a href="#pbp">使用 Personal Basis Profile 创建 CDC 应用程序</a></li>
<!-- <li><a href="#personal">Creating a CDC Application with Personal Profile</a></li>-->
<li><a href="#next">另请参见</a></li>
</ul>
<h2>要求<a name="reqs"></a></h2>
<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="http://www.netbeans.org/downloads/index.html">带有 Java ME 的 NetBeans IDE</a></td>
<td class="tbltd1"> 7.4 </td>
</tr>
<tr>
<td class="tbltd1"><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">Java 开发工具包</a> (JDK)</td>
<td class="tbltd1"> 7</td>
</tr>
<tr>
<td class="tbltd1"><a href="http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html">Oracle Java ME SDK</a></td>
<td class="tbltd1">3.2 或更高版本 </td>
</tr>
</tbody>
</table>
<h2>支持的 CDC 仿真器平台<a name="platforms"></a></h2>
<p>对于 Windows 平台,NetBeans IDE 支持 <a href="http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html">Oracle Java ME SDK</a>。Oracle Java ME SDK 允许您开发 CDC 应用程序。请注意,不同的 CDC 仿真器平台支持不同的开发配置文件。支持它们的主开发配置文件和仿真器是 Personal Basis Profile (Java ME SDK) <!--supports an application development framework for mobile and embedded devices-->
<a href="http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html">详细信息</a></p><!--are:</p>
<ul>
<li>Personal Basis Profile (Java ME SDK) supports an application development framework for mobile and embedded devices
(<a href="http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html">more info</a>)</li>
<li>Personal Profile (Nokia) is the most popular profile for smartphone development (<a href="http://jcp.org/en/jsr/detail?id=62">more info</a>)
<p class="notes"><b>Note:</b> Instructions for adding the Nokia Series 80 Platform SDK for Symbian OS, Java and Personal Profile emulator platform are listed in the <a href="cdcemulator-setup.html"> NetBeans CDC Platform Emulator Setup Guide</a>.</p>
</li>
</ul>-->
<a href="#top">返回页首</a>
<h2><a name="sdkinstall"></a>安装 Oracle Java ME SDK(在 Windows 上)</h2>
<ol>
<li>访问 <a href="http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk/index.html">Java ME SDK Download</a>(Java ME SDK 下载)页。</li>
<li> 单击 "Accept License Agreement"(接受许可协议)选项。</li>
<li>下载 Oracle Java ME SDK 安装文件并将其保存到计算机上的任意位置。</li>
<li>双击此安装文件以运行安装程序,并按照说明操作。<br> 安装完成后,Windows 系统托盘中会显示 "Java (TM) ME Platform SDK Device Manager"(Java (TM) ME Platform SDK 设备管理器)图标 (<img alt="&quot;Java (TM) ME Platform SDK 3.2 Device Manager&quot;(Java (TM) ME Platform SDK 3.2 设备管理器)图标" src="../../../images_www/articles/73/javame/cdc-quickstart/icon.png">)。 </li>
</ol>
<a href="#top">返回页首</a>
<h2><a name="cdcinstall"></a>安装 Oracle Java ME CDC 平台</h2>
<ol>
<li>选择 "Tools"(工具)> "Java Platforms"(Java 平台)。<br> 此时将显示 "Java Platform Manager"(Java 平台管理器)对话框。
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/jpmanager.png" rel="lytebox" title="Java 平台管理器"> <img alt="Java 平台管理器" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/jpmanager-small.png"></a></p></li>
<li>单击 "Add Platform"(添加平台)。</li>
<li>在 "Add Java Platform"(添加 Java 平台)向导的 "Select Platform Type"(选择平台类型)步骤中,选择 "Java ME CDC Platform Emulator"(Java ME CDC 平台仿真器)并单击 "Next"(下一步)。<br> IDE 将显示 "Choose Platform Folder"(选择平台文件夹)步骤。</li>
<li>选择要在其中安装 Java ME SDK 平台的目录(例如,<tt>C:\Java_ME_Platform_SDK_3.4</tt>),然后单击 "Next"(下一步)。</li>
<li>在 "Add Java Platform"(添加 Java 平台)向导的 "Platform Name"(平台名称)面板中,确保选择上一步骤中的所选平台,然后单击 "Finish"(完成)。<br> 现在将在 Netbeans IDE 中注册 Oracle Java ME CDC 平台。
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/cdcregistered.png" rel="lytebox" title="已注册 J2ME 平台"> <img alt="已注册 J2ME 平台" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/cdcregistered-small.png"></a></p></li>
<li>在 "Java Platform Manager"(Java 平台管理器)对话框中,单击 "Close"(关闭)。</li>
</ol>
<a href="#top">返回页首</a>
<h2><a name="plugin"></a>激活 Java ME</h2>
<ol>
<li> 从 IDE 主工具栏中选择 "Tools"(工具)> "Plugins"(插件)。</li>
<li> 在 "Plugins"(插件)对话框中,单击 "Installed"(已安装)标签,并在可用功能列表中选择 "Java ME"。
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/plugins.png" rel="lytebox" title="&quot;Plugins&quot;(插件)对话框"> <img alt="&quot;Plugins&quot;(插件)对话框" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/plugins-small.png"></a></p></li>
<li> 单击 "Activate"(激活)。<br> 在 "Installer"(安装程序)对话框的 "Welcome"(欢迎使用)面板上,单击 "Activate"(激活)。
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/installer.png" rel="lytebox" title="&quot;Installer&quot;(安装程序)对话框"> <img alt="&quot;Installer&quot;(安装程序)对话框" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/installer-small.png"></a></p></li>
<li> 在成功完成激活过程后,单击 "Finish"(完成)。</li>
<li> 单击 "Close"(关闭)以关闭 "Plugins"(插件)对话框。</li></ol>
<p>现在您已设置 NetBeans IDE,可以进行 Mobile 开发了。</p>
<p>在以下各节中,我们将使用每种可用配置文件创建一个 CDC 项目,并且还在 Personal 和 AGUI 配置文件应用程序中使用 IDE 的 GUI 构建器来增强用户界面。 </p>
<a href="#top">返回页首</a>
<h2>创建一个新的 CDC 应用程序 - Personal Basis Profile<a name="pbp"></a></h2>
<p>下面我们将使用 Oracle Java ME SDK 为 Personal Basis Profile (PBP) 1.1 创建一个 CDC 应用程序。 </p>
<ol>
<li>从主窗口中选择 <tt>File</tt>(文件)> <tt>New Project</tt>(新建项目)(Ctrl+Shift+N 组合键)。</li>
<li>从 "Categories"(类别)中,选择 <tt>Java ME</tt>。从 "Projects"(项目)中,选择 <tt>CDC Application</tt>(CDC 应用程序)。单击 "Next"(下一步)。</li>
<li>在 "Name and Location"(名称和位置)页中,将项目命名为 <code>newcdc</code>,然后使 <tt>Create Main Class</tt>(创建主类)复选框保持选中状态。单击 "Next"(下一步)。</li>
<li>在 "Select Platform"(选择平台)页中,保留默认设置 - <code>CDC Java(TM) Platform Micro Edition SDK 3.2</code>(Java 平台)、<code>DefaultCdcPbpPhone1</code>(设备)和 <tt>PBP-1.1</tt>(配置文件),如下图中所示。
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/select-platform.png" rel="lytebox" title="新建 CDC 项目向导 "Select Platform"(选择平台)页"> <img alt="新建 CDC 项目向导 "Select Platform"(选择平台)页" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/select-platform-small.png"></a></p></li>
<li>单击 "Finish"(完成)。IDE 将创建新的应用程序并打开主类窗体。</li>
<li>在 "Source"(源)视图中,找到 <code>g.drawString("Hello, World!", 80, 50);</code> 并添加 <tt>Java</tt> 字样,使其内容显示为 <code>Hello, Java World!</code>
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/hellojava.png" rel="lytebox" title="包含字符串 &quot;Hello Java World!&quot; 的源代码编辑器"> <img alt="包含字符串 &quot;Hello Java World!&quot; 的源代码编辑器" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/hellojava-small.png"></a></p>
</li>
<li>要构建项目,请从主工具栏中选择 "Run"(运行)> "Build Project"(构建项目)。</li>
<li>从主工具栏中选择 "Run"(运行)> "Run Project"(运行项目)以运行您的项目。<br> 该项目在仿真器中启动,并显示修改后的 "Hello World!" 信息。
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/hellojava-emulator.png" rel="lytebox" title="默认颜色电话设备仿真器,该仿真器显示消息 &quot;Hello Java World!&quot;"> <img alt="默认颜色电话设备仿真器,该仿真器显示消息 &quot;Hello Java World!&quot;" border="1" src="../../../images_www/articles/73/javame/cdc-quickstart/hellojava-emulator-small.png"></a></p>
</li>
</ol>
<p>您还可以调试项目并使用 <a href="../../docs/java/junit-intro.html">JUnit 框架</a>为 CDC 项目创建测试。</p>
<!--<a href="#top">top</a>
<a name="personal"></a>
<h2>Creating a New CDC Application - Personal Profile</h2>
<p>Here we create an <em>applet</em> for the Personal Profile using the Nokia
Series 80 Platform SDK for Symbian OS, for Java, Personal Profile. </p>
<p class="notes"><b>Note: </b>See <a href="cdcemulator-setup.html"> NetBeans CDC Platform Emulator Setup Guide</a> for instructions on adding the Nokia Series 80 Platform SDK for Symbian OS, Java and Personal Profile emulator platform, to the IDE.</p>
<ol>
<li>Choose <tt>File</tt> &gt; <tt>New Project</tt>. Under Categories, select
<tt>Java ME</tt>. Under Projects, select the <tt>CDC Application</tt> template. Click Next.</li>
<li>Name the project <tt>S80cdcApplication</tt> and specify a location for
the project on your computer. Leave the <tt>Create Main Class</tt> check box selected.
Click Next.
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/nokias80app.png" rel="lytebox" title="New Project Wizard Name and Location showing S80cdcApplication project">
<img src="../../../images_www/articles/73/javame/cdc-quickstart/nokias80app-small.png" alt="New Project Wizard Name and Location showing S80cdcApplication project" border=1></a></p></li>
<li> In the Select Platform Page, choose the <tt>Nokia S80 Platform</tt>.
<p class="align-center"><a href="../../../images_www/articles/73/javame/cdc-quickstart/nokias80sdk.png" rel="lytebox" title="New Project Wizard Select Platform showing Nokia S80 CDC SDK">
<img src="../../../images_www/articles/73/javame/cdc-quickstart/nokias80sdk-small.png" alt="New Project Wizard Select Platform showing Nokia S80 CDC SDK" border=1></a></p></li>
<li>Click Finish. The IDE creates a new application and opens the main class
form in the GUI Builder, as shown in the following figure. Click on Source
to see the source code for the applet.
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/nokia-screen.png" rel="lytebox" title="The main class form open in the GUI Builder">
<img src="../../../images_www/articles/73/javame/cdc-quickstart/nokia-screen-small.png" alt="The main class form open in the GUI Builder" border=1></a></p>
<p class="notes"><b>Note:</b> The generated code is based on the profile. Here the main class is derived from <code>java.awt.Frame</code>. </p>
</li>
</ol>
<h4>Creating the Application Interface Using the GUI Builder</h4>
<p>You can use the GUI Builder in the same way you use it for regular J2SE development.
In the GUI Builder, right-click the <tt>Main.java</tt> form
and choose <tt>Set Layout</tt> &gt; <tt>Free Design</tt>. Then drag and drop components from
the Palette window into the Design Area of the GUI Builder. </p>
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/nokia-finished.png" rel="lytebox"
title="Sample Form in the GUI Builder">
<img src="../../../images_www/articles/73/javame/cdc-quickstart/nokia-finished-small.png"
alt="Sample Form in the GUI Builder" border=1></a></p>
<p class="notes"><b>Note:</b> Make sure you
only use AWT components in your form. Since all the Nokia Series 80
devices support the Personal Profile, only AWT widgets are available.</p>
<p>For more information on using the IDE's GUI Builder, see the <a href="../../trails/matisse.html">Java GUI Applications Learning Trail</a>.</p>
<p> When you are done, right-click the project in the Projects window and
choose Run from the popup menu. Your application should be displayed in the device emulator.</p>
<p class="align-center">
<a href="../../../images_www/articles/73/javame/cdc-quickstart/app-emulator.png" rel="lytebox"
title="Sample application in the device emulator">
<img src="../../../images_www/articles/73/javame/cdc-quickstart/app-emulator-small.png"
alt="Sample application in the device emulator" border=1></a></p>
<p>You can now run the device in the emulator.</p>
<p>You can also debug the project, and create and debug tests <a href="../java/junit-intro.html">using the JUnit framework</a>.</p>-->
<div class="feedback-box"><a href="/about/contact_form.html?to=6&subject=NetBeans%20CDC%20Development%20Quick%20Start%20Guide">发送有关此教程的反馈意见</a></div><br style="clear:both;"> <a href="#top">返回页首</a>
<h2>另请参见<a name="next"></a></h2>
<blockquote>
<p>以下位置提供了有关使用 IDE 开发 Mobile 应用程序的更多信息:</p>
<ul>
<li><a href="http://wiki.netbeans.org/JavaMESDKSupport">NetBeans IDE 中的 Java ME SDK 支持常见问题解答</a></li>
<!--<li><a href="cdcemulator-setup.html">NetBeans CDC Emulator Platform Setup Guide</a></li>-->
<li><a href="../../../kb/trails/mobility.html">NetBeans Java ME 应用程序学习资源</a></li>
<li><i>使用 NetBeans IDE 开发应用程序</i>中的<a href="http://www.oracle.com/pls/topic/lookup?ctx=nb7400&id=NBDAG1552">开发 Java ME 应用程序</a></li>
</ul>
</blockquote>
<a href="#top">返回页首</a>
</body>
</html>