Sun Java Solaris Communities My SDN Account Join SDN
 

Sun Mobile Device Technology - Code Samples and Apps

 
 

Java ME Sample Applications

PeekAndPick Sample Application is an application that runs on any MIDP-compliant device. It allows you to browse news headlines and story descriptions, select stories that interest you, and have their links e-mailed to your desktop. For information on using PeekAndPick, consult the User's Guide. For information on the internals of PeekAndPick, please see the Design and Implementation article, which includes the full MIDlet source code.

Sun CAT Sun Commerce Animation Tutorial (Sun CAT) is a simple application similar to Neko. Originally developed on the X Windows platform in 1990 by Mayasuki Koba, Neko has been ported to numerous platforms. Neko consists of an animated cat that chases a mouse around a window. Sun CAT will run on any MIDP 1.0 device or emulator. To load the catalog and make mock purchases, your device must be able to make HTTPS connections. Although HTTPS is not mandated by the MIDP 1.0 specification, it is used in this example to demonstrate how credit card information may be securely transmitted from a MIDlet client to a server.

Java Platform Code Samples

This is a master index of Java programming language code samples organized by topic.

Java ME Code Samples

This page provides links to a variety of code samples that use the Java ME APIs.


M-Commerce

Client-Side Download | Server-Side Download
The Mobile Resource Management System" or "m-RMS." sample application is a resource management and tracking system for Mobile Information devices such as PDAs and Phones. m-RMS uses Java ME (CLDC + MIDP) and XML technology and communicates wirelessly over TCP/IP to a backend Java EE framework. Be sure to take a look at the Readme file for the application.


Event Handling

EventEx1.java
This example creates a list of items (Item1 to Item4) and calls the prepare method whenever an item is selected. The testItem# methods, where # is a number between 1 and 4, call the prepare method and set the name of the menu. Example described in MIDP Event Handling

EventEx2.java
In this example a DateField object is created and added to a form. When you click on the date, you can change it by navigating through the calendar. When the date is changed, a message appears. Example described in MIDP Event Handling

EventEx3.java
In this example, the Canvas class is subclassed to use an anonymous inner class, an implementation is provided for the keyPressed and keyReleased methods, and an empty implementation is provided for the paint method. When a key is pressed or released, the application prints the value of that key. Example described in MIDP Event Handling


Network Connections

FirstExample.java
This example uses the StreamConnection class to read the contents of a file referenced by a URL. Example described in MIDP Network Programming Using HTTP and the Connection Framework.

SecondExample.java
This example uses the HttpConnection class to fetch a page. Example described in MIDP Network Programming Using HTTP and the Connection Framework.

ThirdExample.java
This example invokes a CGI script from the HTTP server side, and the results are captured and displayed on the handheld device screen. Example described in MIDP Network Programming Using HTTP and the Connection Framework.


Persistent Storage

Stock.java
This class parses a string obtained from the Yahoo Quote Server or the record store into fields (such as name of stock or price). In this MIDlet, the fields retrieved are the name of the stock, the time, and the price. Example described in MIDP Database Programming using RMS

StockDB.java
This class provides methods that open a new record store, add a new record to the record store, close the record store, and enumerate through the records. Example described in MIDP Database Programming using RMS

QuotesMIDlet.java
This example creates the List Stocks, Add New Stock, Back, Save, and Exit commands, handles command events, connects to the YAHOO Quote Server to retrieve quotes, and invokes methods from Stock and StockDB to parse quotes and add new stocks to the record store. Example described in MIDP Database Programming using RMS


Getting Started

FirstMIDlet.java
This example displays a simple text message and a few commands. Example described in Wireless Application Programming: MIDP Programing and Packaging Basics

HelloMIDlet.java
This example adds a ticker and icons to the HelloMIDlet program that comes with the MIDP installation. A ticker is an advertisement that runs across the top of the screen. Example described in Wireless Application Programming: MIDP Programing and Packaging Basics


Servlets

FirstMidletServlet.java
In this example, FirstMidletServlet is invoked with the GET method and the response is received and displayed on the handset. No input is sent to the servlet. When invoked the servlet sends the Servlet Invoked string and the date back to the client. Example described in MIDP Inter-Communication with CGI and Servlets.

HelloServlet.java
This example sends the Servlet Invoked! message and date to the client. Example described in MIDP Inter-Communication with CGI and Servlets.

PostMidlet.java
This example invokes a CGI script from a MIDlet using the POST method. The input is sent to the script in a message. Example described in MIDP Inter-Communication with CGI and Servlets.

RequestServlet.java
This example retrieves the POST request from the buffer and sends the input values back to the client. Example described in MIDP Inter-Communication with CGI and Servlets.

SecondMidletServlet.java
This exampleprompts the user to enter a first name, and when the user presses the key that corresponds to the Submit command, the RequestServlet is invoked. RequestServlet retrieves the input values of the request from the buffer and returns it back to the client to show that the servlet received the POST request. Example described in MIDP Inter-Communication with CGI and Servlets.


User Interface

GuiTests.java
This example demonstrates how to create various GUI components. The MIDlet for this example allows you to test lists, forms, choices, gauges, text fields, text boxes, for example. Example described in MIDP GUI Programming: Programming the Phone Interface.


Java Card Code Samples

Wallet.java
This example applet turns a smart card into an electronic version of a wallet. Like a wallet, a smart card with the Wallet applet holds digital money, adds money to or subtracts money from the wallet, and indicates the current amount of money in the wallet. Exampled described in How to Write a Java Card applet.


Back to top

Update Your Java Runtime Environment

NetBeans