gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Remote Online Backup
Memory
Laptop Batteries
Promote Your Website
Web Hosting Directory
Promotional Products
Best Price
Promotional Pens
Hurricane Shutters
Online Education
Promos and Premiums
Calling Cards
Baby Photo Contest
Phone Cards

 
Video Games
iPod
Software


  Managing the Modern Network
Sponsored by HP
In a global economy where information crosses the globe in an instant, and where Web-based applications power business, it's more important than ever to ensure your network is safe from threats and optimized to deliver the data your business needs. »
 
  Business Service Management: Generate Revenue Through IT
Sponsored by HP
IT must now help organizations attract, retain and grow customer relationships and increase customer satisfaction. Business service management (BSM) helps lay the foundation by managing services in dynamic support of business requirements. Learn more. »
 
  Evaluating Software as a Service for Your Business
Sponsored by Webroot
Is Software as a Service just hype, or is something really going on here? See if your company can benefit as SaaS tries to change the face of the enterprise. »
 
  Storage Networking: Configuration and Planning
Sponsored by HP
The most critical part of setting up a SAN is configuring each individual disk array. This guide examines configurations for SAN-attached servers and disk arrays, and looks at the future of IP storage. »
 
  Is Your Disaster Recovery Plan Good Enough?
Sponsored by HP
Preparing for a disaster is more often than not part of the storage planning process, and it is one of the most difficult tasks, since it includes local hardware and software, networking equipment, and a test plan. Learn how to get disaster recovery right. »
 
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Building a J2ME Application in NetBeans 4.1
By Dick Wall

Go to page: 1  2  3  4  5  Next  

This article will show you how to use NetBeans 4.1 and the Mobility Pack to write a Java Mobile Edition application quickly and easily. It will demonstrate the simple GUI creation and storage facilities available to a mobile application developer, but will not delve into the online connection capabilities at this point (I will instead save that for the future).

The application I will demonstrate will be a simple vehicle mileage calculator and tracker, allowing you to use a mobile phone or other Java-enabled device to track your average fuel consumption and cost per mile. It is deliberately kept simple and I will note any simplifying assumptions made as the application is presented. It is, of course, entirely up to you if you want to extend this code into something more detailed and useful.

The toolset used for this demonstration is NetBeans 4.1 with the Mobility Pack, both of which are freely available for download from http://www.netbeans.org.

The full project source for this article is available for download from this link.

Getting Started

Before you can start building the application, you will need to get NetBeans 4.1 and the Mobility Pack if you don't already have them.

Both the NetBeans IDE and the Mobility Pack can be downloaded from http://www.netbeans.info/downloads/download.php?type=4.1.

Optionally, enter your e-mail address or uncheck the checkboxes, and click Next to get to the download area.

Be sure to read the Installation Instructions and Mobility Pack release notes using the links on the download page.

Create a New Project

  1. New Project->Mobile->Mobile Application
  2. Project Name: MileageCalculator
  3. Set the project location to where you want it on the disk.
  4. Uncheck the "Create Hello MIDlet" option.
  5. Click Next.
  6. For this application, choose Default Color Phone, CLDC-1.0, and MIDP-1.0 options.
  7. Click Finish.

Create the Visual MIDlet

The core of our application will be a visual MIDlet, which can be thought of as a visual JavaBean for a phone. In fact, this is selling it short—the MIDlet encompasses multiple forms and other GUI views, navigation information between these GUI parts, lifecycle methods for the application, as well as the usual event handlers, methods, and properties.

To create your MIDlet, do the following:

  1. Expand the MileageCalculator node in the Projects pane (if it is not already expanded).
  2. Right-click on the <default package> node and select New->Visual Midlet.
  3. Set the MIDlet name to MileageMidlet, and the MIDP Class Name to the same.
  4. Ignore the MIDlet Icon unless you have a really nice icon to use already (creating icons is beyond the scope of this article).
  5. For the package, type in something that makes sense. For example, I will use com.crispybits.j2me.demo.mileage.
  6. Choose MIDP Version to be MIDP-1.0.
  7. Click Finish.

You should now find yourself looking at the flow designer. There should be an icon that looks like a phone, with a Start Point and an Exit Point. This is one view of the MIDlet; there are two more selectable by buttons at the top of the main pane: Screen Design and Source. Click the Source button to see what is already in the MIDlet at present.

You should see a default constructor (empty) and three lifecycle methods: startApp(), pauseApp(), and DestroyApp(). I will come back to these later.

Creating the GUI

The first part of your application building will be the GUI. There will be three screens in your application. The "main" screen will be the summary page—where you can see the current mileage, MPG, and cost information summarized. There will also be menu options from this screen to the two others you need—an initial setup screen (to enter the vehicle's mileage when you first start using the calculator) and a screen to enter new details when you fill up.

The Summary Page

The summary page will simply give you a run down of the current details for your vehicle, including the current recorded mileage, the current MPG, and the cost per mile since you started keeping records.

Note: the "cost per mile" is simply what the gas is costing.If you want to track maintenance and other items, this application could easily be augmented to do so.

To create the summary page:

  1. Select the MileageMidlet and switch to the Flow Design view in the main pane.
  2. In the inspector pane (top right), right-click on the Screens node and select Add Form.
  3. A new form will appear in the Design view; drag it to the right of the phone icon.
  4. Right-click on the new form, and select Rename, call it SummaryForm.
  5. From the red dot next to Start Point on the phone, drag a line out to the red dot on the SummaryForm. This will make the SummaryForm be displayed as the starting form when you run the application.
  6. Double-click on the SummaryForm to go to the Screen Design for that form.

So far, so good (and nice and easy). You should now see an empty screen ready to take new widgets from the pallette (to the left of the empty form). Before you start adding components, I will take the chance to talk about GUI design in Java ME, and how it compares with desktop applications.

If you have designed a full swing GUI, you will notice some differences when using Java ME to create screens. The most obvious is that there are fewer components. Not so obvious, however, is that (at least for what we are doing) you cannot control the layout of the components as much as you might be used to in swing. The concept of different layout managers does not exist in this GUI builder, nor does it make sense if you stop and think about it.

When designing for a mobile device, you are likely to be dealing with any number of different screen sizes and configurations. Generally speaking, a Java ME application will use all of the screen, not a window within that screen, so that means that the application could be displayed at any resolution from fairly small (say 100x100 pixels for the sake of argument) up to much higher resolutions.

When you think about this, it makes sense that trying to control layout would be very hard. In fact, the device will largely control the layout based on what makes sense to it. I will put down the components you want in the order you want (using a simple flow layout for you Swing folks out there), and leave it to the device to figure out the display details.

Although it may feel a bit strange at first, this model of development is actually quite liberating after you get used to it, and you can certainly slap some GUIs together pretty fast. They might not win any beauty prizes, but they will be functional and they will work on any device (although if you pack a lot onto one screen, you might find yourself scrolling around a lot when running on lower-resolution devices).

The "device handles it" philosophy is carried over even further for the action items (like the menu). You will define the menu actions you want, and the device will figure out how to present them to the user. The likelihood is that the options will be attached as a menu on one of the device's "soft buttons," but it really is down to the device on which the application is running.

Note: If you have a particular device in mind (let's say your phone) and know the resolution, you can right-click on the screen in the Screen Designer, select "Set Screen Size," and then set it to the desired resolution. Although this won't guarantee what it will look like on your device, it will give you a better idea of how much information you can fit on the screen.

Go to page: 1  2  3  4  5  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


EJB/Components Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Data Sheet: IBM Information Server Blade
Whitepaper: XML Processing in Applications--Take the Next Step
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES