J 2 Me
J 2 Me
Contents...........................................................................................................................................1
Mobile Application Development (Through J2ME) LABORATORY ..........................................2
Objective: ....................................................................................................................................2
Week - 1: Installation of Java Wireless Toolkit (J2ME)..............................................................2
Week - 2 Working with J2ME Features:......................................................................................3
Week - 3 Threads & High Level UI:............................................................................................5
Week - 4 Working on Drawing and Images.................................................................................6
Week - 5 Developing Networked Applications using the Wireless Toolkit................................8
Week - 6 Authentication with a Web Server..............................................................................10
Week - 7 & 8 Web Application using J2ME.............................................................................10
Mobile Application Development (Through J2ME) LABORATORY
Objective:
In this lab, a student is expected to design, implement, document and present a mobile
client/server system using standard Java and Java 2 Micro Edition (J2ME) platform. Specifically
it is required to design and implement a system that consists mainly of a mobile client (MC) and
a Proxy Server (PS). MC will be written in J2ME, MIDP 2.0, while PS will be written in
standard Java. It is necessary to use a mobile phone emulator to develop and demonstrate the
experiments.
1) If the Java Development Kit (JDK) is not there or only having the Java Runtime Environment
(JRE) installed, install the latest JDK from http://java.sun.com/javase/downloads/index.jsp.
Current stable release of Java is JDK 6 Update 7 but check the web page in case there are newer
non-beta releases available.
2) Next, download the Java Wireless Toolkit (formerly called J2ME Wireless Toolkit) from:
http://java.sun.com/products/sjwtoolkit/download.html.
3) Run the installer (for example, for Windows it is: sun_java_wireless_toolkit- 2_5_2-
windows.exe). The installer checks whether a compatible Java environment has been pre-
installed. If not, it is necessary to uninstall old versions of Java and perform Step 1 again.
Once after successful installation of Java and the tool kit compile this program and run the
following program in the toolkit.
1. Start -> All Programs -> Sun Java Tool Kit -> Wireless Tool Kit
2. Click New Project – Enter Project Name -> Enter Class Name -> Click on Create Project.
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public HelloWorld(){
super();
}
Working with J2ME Features: Say, creating a Hello World program Experiment with the most
basic features and mobile application interaction concepts (lists, text boxes, buttons, radio boxes,
soft buttons, graphics, etc)
* cut
* copy
* past
* delete
* select all
* unselect all
2.2 Event Handling.
Create an MIDP application which examine, that a phone number, which a user has entered is in
the given format.
* Area code should be one of the following: 040, 041, 050, 0400, 044
* There should 6-8 numbers in telephone number (+ area code)
Week - 3 Threads & High Level UI:
3.1. Create a slide show which has three slides, which includes only text. Program should change
to the new slide after 5 seconds. After the third slide program returns to the first slide.
3.2 High-level UI
Create a MIDP application, which show to the user 5-10 quiz questions. All questions have 4
possible options and one right option exactly. Application counts and shows to the user how
many right answers were right and shows them to user.
3.3 Create a MIDP application, where the user can enter player name and points. The program
saves the information to the record using RMS at MIDP device. Program should also print out
the top 10 player list to the end user. You can use this class in your game if you made own class
for saving and reading record sets.
4.1 Create a slide show which has three slides, which includes pictures at PNG format. Program
should change to the new slide other 5 seconds.
4.2 Create a MIDP application, which draws a bar graph to the display. Data values can be given
at int[] array.
4.3 Create a MIDP application, which draws a bar graph to the display. Data values can be given
at int[] array. You can enter four data (integer) values to the input text field.
Week - 5 Developing Networked Applications using the Wireless Toolkit
1) Click on Wireless Toolkit 2.5.2 under the group: All Programs→Sun Java
(TM) Wireless Toolkit 2.5.2.
2) Click on 'New Project...' button.
3) Enter project name as 'DatagramServer'. Enter MIDlet name as 'DatagramServer'. Note that
the Midlet name is the same as the name of the class in the source code, which extends the
MIDlet class, otherwise the application won’t run.
4) Another window pops up where it is required to select a target platform. Select 'MIDP 1.0'
from the drop down list.
5) After clicking OK, the project is created; and the Wireless Toolkit tells that the name of the
folder where source code files are created. The path of the source code folder is displayed in the
debug output window.
The Wireless Toolkit does not come with an IDE by default so Use any IDE or a text editor like
Notepad.
1) Create a new text file called DatagramServer.java in the source folder of the project. The
exact path of this folder is displayed in the Wireless Toolkit window.
2) Paste contents DatagramServer.java from into the source file.
1) After compiling the project successfully, click on the Run button in the Wireless Toolkit
window.
2) A graphical window depicting a phone handset will appear with the name of your application
highlighted on its screen as shown below.
3) To start the application, click on the right soft-key (marked with a dot) below the ‘Launch’
command.
4) The phone simulator might ask if it is OK to run the network application. Select ‘Yes’ by
clicking on the appropriate soft-key. The server is now up and running.
5) Keep the server running during the creation, compilation and running of the Datagram Client
application.
1) Use the same instance of the Wireless Toolkit that is used for creating and compiling the
Datagram Server project.
2) Click on 'New Project...' button.
3) A new window pops up. Enter project name as 'DatagramClient'. Enter MIDlet name as
'DatagramClient'. Note that the Midlet name is the same as the name of the class in the source
code, which extends the MIDlet class.
4) Another window pops up where one has to select a target platform. Select 'MIDP 1.0' from
the drop down list.
5) After clicking OK, the project is created and the Wireless Toolkit tells where to place the
source code files. The path of the source code folder is displayed in the debug output window as
explained before.
1) Create a new text file called DatagramClient.java in the source folder of the
project.
2) Paste contents DatagramClient.java into the source file.
3) Then click on the Build button in the Wireless Toolkit window. If the compilation is OK, it
will say Build Complete in the window's debug output window, otherwise it will show the errors.
Note: In the source code, use the System.out.println() statement to output debug information to
this window.
1) After compiling the project successfully, click on the Run button in the Wireless Toolkit
window.
2) A graphical window depicting a phone handset will appear with the name of the application
highlighted on its screen.
3) To start the application, click on the right soft-key (marked with a dot) below the ‘Launch’
command.
4) The phone simulator might ask if it is OK to run the network application. Select ‘Yes’ by
clicking on the appropriate soft-key. The client is now up and running.
5) When the client executes on the phone simulator, one should see a text box with the caption
'Message'. Enter any message and press the right soft-key (corresponding to Send). If the client-
server application is working properly, the screen of the server phone will display the message
sent by the client and the client screen will now display a message sent by the server in response.
The response message from the server is the original client message in reverse.
6) Try various features of the phone simulator including the different look-and feel options.
6.1 Write a sample program to show how to make a SOCKET Connection from j2me
phone.
This J2ME sample program shows how to how to make a SOCKET Connection from a J2ME
Phone. Many a times there is a need to connect backend HTTP server from the J2ME
application. shows how to make a SOCKET connection from the phone to port 80.
This J2ME sample program shows how to display a simple LOGIN SCREEN on the J2ME
phone and how to authenticate to a HTTP server.
Many J2ME applications for security reasons require the authentication of the user. This free
J2ME sample program, shows how a J2ME application can do authentication to the backend
server.
Note: Use Apache Tomcat Server as Web Server and Mysql as Database Server.
The following should be carried out with respect to the given set of application domains:
(Assume that the Server is connected to the well-maintained database of the given domain.
Mobile Client is to be connected to the Server and fetch the required data value/information)
Divide Student into Batches and suggest them to design database according to their domains and
render information according the requests.