Docsity

AnroidANDROIDANDROIDANDROID, Exercises of Programming Methodologies

Partial preview of the text

Download AnroidANDROIDANDROIDANDROID and more Exercises Programming Methodologies in PDF only on Docsity!

LAB MANUAL

ON

MOBILE APPLICATION DEVELOPMENT LAB

IV B. Tech I semester (JNTUH-R15)

Mr. D.RAHUL

Assistant Professor

INFORMATION TECHNOLOGY

INSTITUTE OF AERONAUTICAL ENGINEERING

(Autonomous)

DUNDIGAL, HYDERABAD - 500 043

INSTITUTE OF AERONAUTICAL ENGINEERING

(Autonomous)

DUNDIGAL – 500 043, HYDERABAD

MOBILE APPLICATION DEVELOPMENT LAB

OBJECTIVES: ļ‚· 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. ļ‚· It may be necessary to use other components or existing resources (servers) as needed. For instance a database local to PS or a web service available on the Internet that can be invoked by the PS. .

LIST OF EXPERIMENTS: S.NO List of Experiments Page No. 1 Installation of Java Wireless Toolkit (J2ME) 10

2 Working with J2ME Features:

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)

Create a program which creates to following kind of menu. ***** cut ***** copy ***** past ***** delete ***** select all ***** unselect all

11

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.

22

4 4.1. Working on Drawing and Images

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.

41

6 6.1. Authentication with a Web Server 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.6.2. Login to HTTP Server from a J2ME Program 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.

56

7 & 8 Week - 7 & 8 Web Application using J2ME 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) Students Marks Enquiry Town/City Movie Enquiry Railway/Road/Air (For example PNR) Enquiry/Status Sports (say, Cricket) Update Town/City Weather Update Public Exams (say Intermediate or SSC)/ Entrance (Say EAMCET) Results Enquiry

60

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. It may be necessary to use other components or existing resources (servers) as needed. For instance a database local to PS or a web service available on the Internet that can be invoked by the PS.

Week - 1: Installation of Java Wireless Toolkit (J2ME)

  1. If the Java Development Kit (JDK) is not theory 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.

Steps to run this program in toolkit: Start -> All Programs -> Sun Java Tool Kit -> Wireless Tool Kit Click New Project – Enter Project Name -> Enter Class Name -> Click on Create Project. Choose appropriate API Selection and Configurations. Place Java Source file in WTK2.1 / WTK2.2\apps\projectname\src Build the Project. Run the Project. import javax.microedition.lcdui.; import javax.microedition.midlet.;

public class HelloWorld extends MIDlet{ private Form form; private Display display;

public HelloWorld(){ super (); }

public void startApp(){ form = new Form("Hello World"); String msg = "Hello World!!!!!!!"; form.append(msg); display = Display.getDisplay( this ); display.setCurrent(form);

ch=new ChoiceGroup("Edit",Choice.EXCLUSIVE); ch.append("cut",null); ch.append("copy",null); ch.append("paste",null); ch.append("delete",null); ch.append("select all",null); ch.append("unselect all",null); ch.setSelectedIndex(1, true); command=new Command("Select list item",Command.OK,1); form=new Form(""); form.append(ch); form.addCommand(command); form.setCommandListener(this); st=new StringItem("",""); } public void startApp() { display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command command,Displayable displayable) { if(command==command) { st.setText(""); st.setText("your selected option is "+ch.getString(ch.getSelectedIndex())); form.append(st); } } } Output:

**2.2 Event Handling. Create a menu which has the following options:

  • cut - can be on/off
  • copy - can be on/off
  • paste - can be on/off
  • delete - can be on/off
  • select all - put all 4 options on
  • unselect all - put all 4 options off**

Program:

import javax.microedition.midlet.; import javax.microedition.lcdui.; public class MenuEvents extends MIDlet implements CommandListener,ItemStateListener { public ChoiceGroup ch; public ChoiceGroup ch1; public Form form; public Form form1; public Display display; public Command View; public Command Exit; public Command Back; public StringItem options; public Item item; public MenuEvents() { display=Display.getDisplay(this); form=new Form(""); form1=new Form("Selcted Options are"); ch=new ChoiceGroup("Preferences",Choice.MULTIPLE); ch.append("cut",null); ch.append("copy",null); ch.append("paste",null); ch.append("delete",null); ch.setSelectedIndex(1, true); form.append(ch); ch1=new ChoiceGroup("",Choice.EXCLUSIVE);

else if(displayable==form1) { if(command==Back) { display.setCurrent(form); options.setText(""); } } } public void itemStateChanged(Item item) { if(item==ch1) { int i=0; int size=ch.size(); while(i<size)< p=""> </size)<> { if(ch1.getSelectedIndex()==0) ch.setSelectedIndex(i, true); else ch.setSelectedIndex(i, false); i++; } } } } Output:

**2.3. Input checking 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)**

Program: import javax.microedition.midlet.; import javax.microedition.lcdui.;

public class InputChecking extends MIDlet implements CommandListener {

public Form form1; public TextField textfield1; public Command exitCommand; public Command okCommand; public StringItem st; public Display display;

public InputChecking() {

display=Display.getDisplay(this); form1=new Form("Insert the Phone number"); exitCommand=new Command("Exit",Command.EXIT,1); okCommand=new Command("Ok",Command.OK,1); st=new StringItem("Phone Number is ",""); textfield1=new TextField("Phone;","",30,TextField.ANY); form1.append(textfield1); form1.addCommand(okCommand); form1.addCommand(exitCommand); form1.setCommandListener(this);

} public void startApp() { display.setCurrent(form1); }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }

form1.append(st);

} } }

Output:

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.

import javax.microedition.midlet.; import javax.microedition.lcdui.; public class SlideShow extends MIDlet implements CommandListener {

public Form slide1; public Form slide2; public Form slide3; public Command Exit; public Display display; public SlideShow() { display=Display.getDisplay(this); Exit=new Command("Exit",Command.EXIT,1); slide1=new Form("Slide1"); slide1.append("This is Slide number 1"); slide1.addCommand(Exit); slide2=new Form("Slide2"); slide2.append("This is Slide number 2"); slide2.addCommand(Exit); slide3=new Form("Slide3"); slide3.append("This is Slide number 3"); slide3.addCommand(Exit); slide1.setCommandListener(this); slide2.setCommandListener(this); slide3.setCommandListener(this); } public void startApp() { Thread runner = new Thread(new ThreadRunner(display,slide1,slide2,slide3)); runner.start(); }

public void pauseApp() { }

public void destroyApp(boolean unconditional) { }