Oracle® Java ME Embedded Getting Started Guide for the Windows Platform Release 3.3 E35132-02 |
|
Previous |
Next |
This chapter describes the NetBeans integrated development environment. NetBeans provides a rich, visual environment for developing embedded applications and numerous tools to improve the programming process.
Oracle Java ME SDK provides two plugins for working with NetBeans:
Java ME SDK Tools plugin
Java ME SDK Demos plugin
The Java ME SDK Demos plugin is optional, but recommended.
To download the Oracle Java ME SDK Plugins file for NetBeans (oracle-jmesdk-3-3-rr-nb-plugins.zip
) go to the following location:
http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk
There are two ways to install the Oracle Java ME SDK Plugins:
Note: Using the NetBeans Update Center to install the plugins is recommended. However, installing the plugins manually also works. |
To get the plugins ready for installation, start NetBeans as described in Chapter 1
To install the NetBeans Plugins using the NetBeans Update Center:
Select Tools > Plugins to open the NetBeans Plugins manager, as shown in Figure 2-1.
Click the Settings tab. This displays the available update centers, as shown in Figure 2-2.
Click the Add button. In the new window, type a provider name and a URL for the location that contains the plugin center files, as shown in Figure 2-3.
When plugins are detected, they are displayed on the Available Plugins tab. If you do not see them, click the Check for Updates button.
Locate the Oracle Java ME SDK plugins.
In the Install column check the desired plugins, then click the Install button.
Figure 2-4 The Oracle Java ME SDK Plugins
Restart NetBeans.
In the Plugins Manager Settings tab, enable all available update centers.
In the Installed tab, check Show details (above the plugin list) and sort by category to easily find the Java ME SDK Tools plugins.
Make sure the plugins you installed are active (with a green check mark), as shown in Figure 2-5.
If the Oracle Java ME SDK plugins are not Active, check the Select boxes for the plugins and click Activate.
Figure 2-5 The Plugins Manager Installed Tab
The Oracle Java ME SDK is ready to use. For more information on how to verify your plugin installation, see
To install the NetBeans Plugins manually.
Extract the contents of the NetBeans Plugins file to a directory on your local machine. Make note of the location.
Open the NetBeans Plugins Manager. Select:
Tools > Plugins
Uninstall previous plugins.
Go to the Installed tab and click Show details, as shown in Figure 2-6.
Check Java ME SDK Tools and Java ME SDK Demos.
Note: If the previous plugins have already been uninstalled, go to Step 6. |
Figure 2-6 NetBeans Plugins Manager Window
Click Uninstall.
Restart when requested.
Re-open the Plugins Manager and click the Downloaded tab, as shown in Figure 2-7.
Click the Add Plugins button.
Figure 2-7 The Downloaded Tab and Add Plugins Button
In the file browser, go to the directory in which you have extracted the contents of the NetBeans Plugins.
Select all the .nbm
files and click Open, as shown in Figure 2-8.
Go to the Downloaded tab and select all downloaded plugins, as shown in Figure 2-9, and click Install.
When the NetBeans IDE Installer screen is displayed, as shown in Figure 2-10, click Next.
Accept the license terms and click Install.
If additional Validation screens appear, click Continue.
Click Finish to restart NetBeans.
Select Tools > Plugins to display the Plugins screen.
In the Installed tab, check Show details and click Category to sort the plugins.
Find the Java ME SDK Tools and Java ME SDK Demos plugins in the list.
Make sure the plugins you installed are Active (you should see a green check mark), as shown in Figure 2-6.
If the Oracle Java ME SDK plugins are not Active, check the Select boxes for the plugins and click Activate.
When your Oracle Java ME SDK plugins are Active, click Close.
The Oracle Java ME SDK is ready to use. For more information on how to verify your plugin installation, see
Once you have installed the Oracle Java ME SDK Plugins into NetBeans (using the Update Center or by manual installation), the Oracle Java ME SDK platform is installed into the NetBeans IDE. To verify a successful installation, do the following:
To verify the Active Device Manager, select Tools > Java ME > Active Device Manager, and select the latest version (Oracle Java ME SDK 3.3).
To view available Oracle Java ME SDK 3.3 devices, select Tools > Java ME > Device Selector. The ME SDK devices are listed, as shown in Figure 2-11.
To display the new Oracle Java ME SDK platform, choose Tools > Java Platforms. This displays the Java Platform Manager with the new platform, as shown in Figure 2-12.
The Oracle ME SDK Platform is now ready for you to work with, to create a new project and develop code, as shown in the following sections.
In this section, you create a sample IMlet file, IMletDemo.java
, from the code provided in Example 2-1. This IMlet file is used in the next section, "Creating a New Project".
Copy the code shown in Example 2-1 into a text file. Use Notepad rather than WordPad, to avoid any unneeded extra characters.
Name the file IMletDemo.java
and Save. Set the file aside for now.
Example 2-1 Code for the Sample IMletDemo.java Project in NetBeans
package imletdemo; import javax.microedition.midlet.MIDlet; public class IMletDemo extends MIDlet { boolean bFirst = false; boolean loopFlag = true; public void startApp() { if (bFirst = false) { try { // Perform startup operations } catch (Exception ex) { ex.printStackTrace(); return; } bFirst = true; } else { System.out.println("IMlet Demo is already started..."); } // Start program here } public void pauseApp() { // Pause the application } public void destroyApp(boolean unconditional) { bFirst = false; // Close all resources that have been opened } }
This section walks you through creating a new embedded project using the Oracle Java ME SDK and NetBeans platforms.
Choose File > New Project. The New Project dialog box appears.
Choose Java ME from the Categories list and Embedded Application from the Projects list, as shown in Figure 2-13.
Press the Next button. This shows the The New Embedded Application dialog box, with EmbeddedApplication1
in the Name and Location panel.
Enter IMletDemo
as the Project Name.
Accept the default Project Location or browse to select it. Ensure that the Create Default Package and IMlet Class option is checked, as shown in Figure 2-14. Click Next.
The Default Platform Selection is displayed. In the Emulator Platform box, choose "Oracle Java(TM) Platform Micro Edition 3.3." Choose "IMPNGDevice1" for the Device, "CLDC 1.1" for the Device Configuration, and "IMP-NG" for the Device Profile, as shown in Figure 2-15. Press Finish.
Figure 2-15 Setting the New Default Platform
This More Configurations Selection box is displayed, as shown in Figure 2-16. Accept the defaults or add additional configurations. Press Finish.
The NetBeans New Project screen is displayed for the project you have just created, containing default minimal sample code, as shown in Figure 2-17
Now you can update the generic project with the sample code you created earlier in The NetBeans Projects window looks like Figure 2-18.
Right click to select IMlet.java
in the Projects window.
Select Refactor --> Rename to display the Rename Class IMlet dialog box.
In the Rename Class IMlet dialog box, enter IMletDemo
. Ensure that Apply Rename on Comments is checked, as shown in Figure 2-19. Press Refactor.
Figure 2-19 The Rename Class IMlet Dialog Box
This changes the name in the Projects window to IMletDemo.java
, as shown in Figure 2-20. Right click IMletDemo.java
and select Properties.
Figure 2-20 The IMletDemo Projects Window
This displays the IMletDemo.java
- Properties window. To see the path to the location of the newly-refactored IMletDemo.java
file, look in the All Files line, as shown in Figure 2-21. Make a note of this path.
Figure 2-21 The IMletDemo Properties Window
Take the IMletDemo.java
file you created in "Creating a Sample IMlet File" and use it to overwrite the IMletDemo.java
file in the path location you have just noted. When it asks you to confirm the File Replace, click Yes.
This changes the content of the NetBeans Project window to the content contained in the newly-added IMletDemo.java
file, as shown in Figure 2-22. (If it does not double-click IMletDemo.java
in the Projects window.
Figure 2-22 The NetBeans Project Window with the IMletDemo Project
Clean and build the IMletDemo project by clicking on the hammer-and-broom icon in the NetBeans toolbar, as shown in Figure 2-23, or by selecting Run > Clean and Build Project (IMletDemo).
Figure 2-23 The NetBeans Toolbar and Menus
Run the newly cleaned and built IMletDemo project by selecting the green right-arrow icon in the NetBeans toolbar or by selecting Run > Run Project (IMletDemo).
When the Run is successful, the IMPNGDevice1 emulator starts with the IMletDemo Suite running, as shown in Figure 2-24.
Figure 2-24 The NetBeans Emulator Window Running the IMletDemo Project
For more information about the emulator, see Chapter 3, "Using the Emulator".