Manual

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 48

LABORATORY MANUAL

MOBILE COMPUTING LAB


(IV YEAR / VII TH SEMESTER)

DEPARTMENT OF INFORMATION TECHNOLOGY JAYAM COLLEGE OF ENGINEERING & TECHNOLOGY DHARMAPURI-636813


PHONE NO: 04342-257251-55 FAX: 04342-257289 www.collegejayam.org Email: [email protected] better education better tomorrow

MOBILE COMPUTING LAB LIST OF EXERCISES BRANCH: B.TECH.IT Subject Name/Code: Mobile Computing Lab Year/Semester: IV / VII LIST OF EXERCISES 1. Study of WML and J2ME simulators 2. Design of simple Calculator having +,,,* and / using WML/J2ME 3. Design of Calendar for any given month and year using WML/J2ME 4. Design a Timer to System Time using WML/J2ME 5. Design of simple game using WML/J2ME 6. Animate an image using WML/J2ME 7. Design a personal phone book containing the name, phone no., address, e-mail, etc. 8. Simulation of Authentication and encryption technique used in GSM 9. Browsing the Internet using Mobile phone simulator 10. Study of GlomoSim Simulator

Mobile Computing Lab LESSON PLAN Name of Faculty: Subject Name/Code: Mobile Computing Lab Branch: B.Tech.IT Year/Semester: IV / VII Date of Completion

S.No Name of Exercise 1. Study of WML and J2ME simulators Design of simple Calculator having +,,,* and / using WML/J2ME

2.

3.

Design of Calendar for any given month and year using WML/J2ME

4. 5. 6.

Design a Timer to System Time using WML/J2ME Design of simple game using WML/J2ME Animate an image using WML/J2ME Design a personal phone book containing the name, phone no., address, e-mail, etc.

7.

8.

Simulation of Authentication and encryption technique used in GSM

9. 10.

Browsing the Internet using Mobile phone simulator Study of GlomoSim Simulator

Experiment No: 1 STUDY OF WML AND J2ME SIMULATORS Aim: To learn WML and J2ME. INTRODUCTION TO J2ME: Traditional computing devices use fairly standard hardware configurations such as display, keyboard, large amount of memory and permanent storage. However new breed of computing devices lacks hardware configuration. J2ME is specially designed for developing applications for small computing devices such as cell phones, PDA etc.

Figure - Fragmentation of Java 2 J2ME Configurations: Configuration defines the JVM for a particular small computing device. Two types of configuration haves been defined. 1) CLDC (Connected limited Device configuration) CLDC is used for the devices with the limited resources. CLDC devices use stripped version of JVM called KVM. CLDC devices are mobile phones, PDA etc.

2) CDC (Connected device configuration) CDC devices use complete JVM. CDC devices are set-top box, Home appliances such as Air conditioner etc..

Figure - CLDC: Connected Limited Device Configuration J2ME Profiles: Profile consists of classes that enable developers to implements features found in a related group of small computing devices. Many profiles are available. Here we use MIDP (Mobile Information Device Profile) MIDP is used with CLDC configuration that provides classes for local storage, a user interface and networking capabilities. Other profiles are Game profile, Foundation profile, RMI profile and many more.. J2ME Architecture:

Java Virtual Machine layer: This layer is an implementation of a Java Virtual Machine that is customized for a particular device's host operating system and Supports a particular J2ME configuration.

Configuration layer: The configuration layer defines the minimum set of Java Virtual Machine features and Java class libraries available on a particular category of devices. In a way, a configuration defines the commonality of the Java platform features and libraries that developers can assume to be available on all devices belonging to a particular category. This layer is less visible to users, but is very important to profile implementers. Profile layer: The profile layer defines the minimum set of application programming interfaces (APIs) available on a particular family of devices. Profiles are implemented upon a particular configuration. Applications are written for a particular profile and are thus portable to any device that supports that profile. A device can support multiple profiles. This is the layer that is most visible to users and application providers. MIDP layer: The Mobile Information Device Profile (MIDP) is a set of Java APIs that addresses issues such as user interface, persistence storage, and networking. MIDlet Programming: A MIDlet is class, which is controlled by the application manager. A MIDlet class must contain three abstract methods that are called by application manager. public class class-name extends MIDlet { public void startApp(){ } public void pauseApp() { } public void destroyApp( unconditional boolean) { } } STUDY OF WML (Wireless Markup Language): WML (Wireless Markup Language) is a markup language based on XML, and is intended for the use in specifying content for narrow band devices such as mobile phones. It mainly specifies how to display text contents on a mobile device. WML is designed with the constraints of small narrow band devices in mind. This constraint includes small display and limited user input facilities, limited memory and computational resources. It is a content format for devices that implement the Wireless Application Protocol (WAP) specification, such as mobile phones. A WAP gateway sits between mobile devices using the WAP protocol and the World Wide Web passing pages from one to other much like a proxy.

This translates s pages into a form suitable for the mobiles such as WML pages. WML pages are stored on a web server. They are accessed by a WAP gateway, which sits between mobile devices and WWW, passing pages from one to other much like a proxy. This process is hidden from the phone, so it may access the page in the same way as a browser accesses HTML using a URL. WML TAGS: WML document is called a DECK. Data in a DECK is structured into one or more Cards(pages). 1) <wml> </wml> WML deck is defined by a <wml> tag. This tag conatins cards and information about WML document. 2) <card> </card> WLL deck contains one or more cards. The <card> can contain text,links , tables images etc. The id attribute of the card sets a unique name for the card. 3) <do> </do> The <do> tag can be used to activate a task when the user clicks on a word/phrase on the screen. It has following attributes: type: Required. Defines the type of the do element. Type can be accept, prev, help, reset, delete id: Sets a unique name for the element. lable: Creates a lable for the do element name : Defines name for the do element. 4) <go/> The <go> tag represents the action of going to a new card. Where to go is specified by href attribute. 5) <select> and <option> tag The <option> tag is used to define the options in the selectable list. The group of selectable list identified by the name attribute mentioned in the select tag. E.g <select name = name> <option value = some value> text </option> <option value = some value> text </option> </select> 6) <optgroup> </optgroup> The <optgroup> tag defines a group of options in a selectable list. <select>

<optgroup> <option>text</option> <option>text</option> </optgroup> <optgroup> <option>text</option> <option>text</option> </optgroup> </select> 7) <template> </template> The <template> tag defines a template for all the cards in a deck. The "code" in the <template> tag is added to each card in the deck.

CONCLUSION: Basic tags of WML and basics of J2ME have been studied.

EXERCISE NO.2 DESIGN OF HELLO WORLD

AIM: To Design a simple Hello World using WML/J2ME. DESCRIPTION:


This coding is done just to display the hello world message in mobile. SOURCE CODE: import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HelloMidlet extends MIDlet implements CommandListener { private Form mMainForm; public HelloMidlet() { mMainForm = new Form("HelloMidlet"); mMainForm.append(new StringItem(null, "Hello, MIDP! \n\nYou and me - we're gonna make sweet MIDlets together! ")); mMainForm.addCommand(new Command("Exit", Command.EXIT, 0)); mMainForm.setCommandListener(this);} public void startApp() { Display.getDisplay(this).setCurrent(mMainForm);} public void pauseApp() {} public void destroyApp(boolean unconditional) {} public void commandAction(Command c, Displayable s) { notifyDestroyed(); }}

OUTPUT:

RESULT: Thus the exercise for designing a simple HelloWorld USING WML/J2ME had been completed successfully. EXERCISE NO.3 DESIGN OF DATE & TIME

AIM: To Design a simple Application to display Date & Time using WML/J2ME. DESCRIPTION: In this exercise we are going to show the current date and time on the screen. Like core Java J2ME too use the same java.util package to show the current date as well as current time on the screen. In this Midlet we have to set the current date and time as date & time. That's why it is going to show you current date and time, every time you runs the application. SOUCE CODE:
package com.j2me.part1; import java.util.Date; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; public class DateTimeApp extends MIDlet { Alert timeAlert; public DateTimeApp() { timeAlert = new Alert("Alert!"); timeAlert.setString(new Date().toString()); } public void startApp() { Display.getDisplay(this).setCurrent(timeAlert);} public void pauseApp() {} public void destroyApp(boolean unconditional) { }}

OUTPUT:

OUTPUT: Thus the exercise for designing a simple Application of displaying Date & Time using WML/J2ME had been completed successfully

EXERCISE NO.4

DESIGN OF SIMPLE CALCULATOR AIM: To Design a simple Calculator having +,,,* and / using WML/J2ME. DESCRIPTION: The calculator supports buttons like +-, X, + or -, = backspace, ? Etc. Also the calculator has the euro and franc buttons. Users will find this little pocket calculator on their mobile phones very useful.

SOURCE CODE: import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet;

public final class CalculatorMIDlet extends MIDlet implements CommandListener { private static final int NUM_SIZE = 20; private final Command exitCmd = new Command("Exit", Command.EXIT, 2); private final Command calcCmd = new Command("Calc", Command.SCREEN, 1); private final TextField t1 = new TextField(null, "", NUM_SIZE, TextField.DECIMAL); private final TextField t2 = new TextField(null, "", NUM_SIZE, TextField.DECIMAL); private final TextField tr = new TextField("Result", "", NUM_SIZE, TextField.UNEDITABLE); private final ChoiceGroup cg = new ChoiceGroup("", ChoiceGroup.POPUP, new String[] { "add", "subtract", "multiply", "divide" }, null); private final Alert alert = new Alert("Error", "", null, AlertType.ERROR); private boolean isInitialized = false; protected void startApp() { if (isInitialized) { return; } Form f = new Form("FP Calculator"); f.append(t1); f.append(cg); f.append(t2); f.append(tr); f.addCommand(exitCmd);

f.addCommand(calcCmd); f.setCommandListener(this); Display.getDisplay(this).setCurrent(f); alert.addCommand(new Command("Back", Command.SCREEN, 1)); isInitialized = true; } protected void destroyApp(boolean unconditional) { } protected void pauseApp() { } public void commandAction(Command c, Displayable d) { if (c == exitCmd) { destroyApp(false); notifyDestroyed(); return; } double res = 0.0; try { double n1 = getNumber(t1, "First"); double n2 = getNumber(t2, "Second"); switch (cg.getSelectedIndex()) { case 0: res = n1 + n2; break; case 1: res = n1 - n2; break; case 2: res = n1 * n2; break;

case 3: res = n1 / n2; break; default: } } catch (NumberFormatException e) { return; } catch (ArithmeticException e) { alert.setString("Divide by zero."); Display.getDisplay(this).setCurrent(alert); return; } String res_str = Double.toString(res); if (res_str.length() > tr.getMaxSize()) { tr.setMaxSize(res_str.length()); } tr.setString(res_str); } private double getNumber(TextField t, String type) throws NumberFormatException { String s = t.getString(); if (s.length() == 0) { alert.setString("No " + type + " Argument"); Display.getDisplay(this).setCurrent(alert);

throw new NumberFormatException(); } double n; try { n = Double.parseDouble(s); } catch (NumberFormatException e) { alert.setString(type + " argument is out of range."); Display.getDisplay(this).setCurrent(alert); throw e; } return n; } }

OUTPUT:

RESULT: Thus the exercise for designing a simple Calculator having +,,,* and / using WML/J2ME had been completed successfully.

EXERCISE NO.5 DESIGN OF CALENDAR AIM: To Design a Calendar for any given month and year using WML/J2ME. DESCRIPTION: In this exercise we are going to show the current date and time on the screen. Like core Java J2ME too use the same java.util package to show the current date as well as current time on the screen. In this Midlet we have to set the current date and time as date & time. That's why it is going to show you current date and time, every time you runs the application. SOURCE CODE:
import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import java.util.Date; import java.util.TimeZone; public class CalenderMIDlet extends MIDlet { private Form form; private Display display; private DateField calender; private static final int DATE = 0; public CalenderMIDlet() { calender = new DateField("Date In:", DateField.DATE, TimeZone.getTimeZone("GMT")); } public void startApp() { display = Display.getDisplay(this); Form form = new Form("Calender");

form.append(calender); display.setCurrent(form); } public void pauseApp(){} public void destroyApp(boolean destroy) { notifyDestroyed(); } }

OUTPUT:

RESULT: Thus the exercise for designing a Calendar for any given month and year using WML/J2ME had been completed successfully.

EXERCISE NO.6 DESIGN A TIMER TO SYSTEM TIME AIM: To Design a Timer to System Time using WML/J2ME DESCRIPTION: Each MIDlet must extend the abstract MIDlet class found in the javax.microedition.midlet ackage, much like creating an applet by extending the java.applet.Applet class. At the minimum, your MIDlet must override three methods of this abstract class, startApp(), pauseApp(), and destroyApp(boolean unconditional). Our Date-Time MIDlet does not need user interactivity. It needs to display the current date and time for a few seconds when the user executes the MIDlet. SOURCE CODE:
import java.util.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class TimerMIDlet extends MIDlet implements CommandListener { private Display display; private Form form; private Command exit, stop; private Timer timer; private TestTimerTask task; private int count = 0; public TimerMIDlet() { display = Display.getDisplay(this); form = new Form("Timer Example"); exit = new Command("Exit", Command.EXIT, 1); stop= new Command("Stop", Command.STOP, 2); form.append("Please wait for timer.. \n"); form.addCommand(exit);

form.addCommand(stop); form.setCommandListener(this); } public void startApp () { timer = new Timer(); task = new TestTimerTask(); timer.schedule(task,5000,3000); display.setCurrent(form); } public void pauseApp (){ } public void destroyApp (boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { String label = c.getLabel(); if (label.equals("Stop")) { timer.cancel(); } else if (label.equals("Exit")) { destroyApp(true); } }

private class TestTimerTask extends TimerTask { public final void run() { form.append("Timer Execute Count: " + ++count + "\n"); }}}

OUTPUT:

RESULT: Thus the given exercise for designing a Timer to System Time using WML/J2ME had been completed successfully.

EXERCISE NO.7 DESIGN OF SIMPLE GAME AIM: To Design a simple game using WML/J2ME DESCRIPTION: J2ME is an interesting environment for games. With basic knowledge of Java, preinstalled NetBeans and J2ME Wireless Toolkit, you can make simple, funny 2D games that are capable of running on your own mobile devices. A J2ME Game Canvas Example This example illustrates how to create a game using GameCanvas class. In this example we are extending GameCanvas class to draw the circle and rotate the circle continuously. The GameCanvas class has following methods:

flushGraphics():- This is the void type method, it flushes to display on the off-screen buffer. flushGraphics(int x, int y, int width, int height):- This is the void type method, it flushes to display of specified region on the off-screen buffer. getGraphics():- This is used to get the graphics objects. getKeyStates():- This is the integer type variable, it is used to find the states of the key. paint(Graphics g):- This is also the void type method, it is used to paint the canvas.

Other commands, input event, etc methods inherited from Canvas class. The Canvas class has following methods:

getGameAction(int keyCode) getHeight() getKeyCode(int gameAction) getKeyName(int keyCode) getWidth() hasPointerEvents()

hasPointerMotionEvents() hasRepeatEvents() hideNotify() isDoubleBuffered() keyPressed(int keyCode) keyReleased(int keyCode) keyRepeated(int keyCode) paint(Graphics g) pointerDragged(int x, int y) pointerPressed(int x, int y) pointerReleased(int x, int y) repaint() repaint(int x, int y, int width, int height) serviceRepaints()

SOURCE CODE:
import javax.microedition.lcdui.*; import javax.microedition.lcdui.game.*; import javax.microedition.midlet.*; public class CanvasGame extends MIDlet { private Command back; private Display display; final SweepGame game = new SweepGame(); public void startApp() { back = new Command("Back", Command.BACK, 0); game.start(); game.addCommand(back); game.setCommandListener(new CommandListener(){ public void commandAction(Command c, Displayable s) { game.stop();

notifyDestroyed(); } }); display = Display.getDisplay(this); display.setCurrent(game); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} } class SweepGame extends GameCanvas implements Runnable { private boolean move; private int radius; private int diameter; private int interval; public SweepGame() { super(true); radius = 0; diameter = 10; interval = 0; } public void start() { move = true; Thread t = new Thread(this); t.start(); } public void stop() { move = false; } public void render(Graphics g) { int width = getWidth();

int height = getHeight(); g.setColor(183,251,121); g.fillRect(0, 0, width - 1, height - 1); int x = diameter; int y = diameter; int w = width - diameter * 2; int h = height - diameter * 2; for (int i = 0; i < 17; i=i+2) { g.setColor(((17 - i) * 15 - 7),20,((17 - i) * 15 - 7)); g.fillArc(x, y, w, h, radius + i * 10, 10); g.fillArc(x, y, w, h, (radius + 180) % 360 + i * 10, 10); } } public void run() { Graphics g = getGraphics(); while (move) { radius = (radius + 1) % 360; render(g); flushGraphics(); try { Thread.sleep(interval); } catch (InterruptedException ie) {} }}}

OUTPUT:

RESULT: Thus the given exercise for designing simple game using WML/J2ME had been completed successfully.

EXERCISE NO.8 IMAGE ANIMATION AIM: To animate an image using WML/J2ME. DESCRIPTION: There are two types of images that can be displayed. 1) Immutable 2) Mutable Immutable images are loaded from a file or other resources and cannot be modified once the image is displayed. Examples. Icon s associated with MIDlets is immutable. A mutable image is drawn on the Canvas using methods available in Graphics class. An immutable image can be drawn on the screen as well as on Canvas. Where as mutable image is drawn only on the canvas. The Canvas Class: Each MIDlet has a one instance of the Display class, and the Display class has a one derived class called 'displayable'. Everything a MIDlet displays on the Screen is created by an instance of a Displayable class. The Display class hierarchy is shown below: public class Displayable public abstract class Displayable public abstract class Screen extends Displayable public abstract class Canvas extends Displayable public class Graphics The screen class is used to create high-level components. the Canvas class is used to gain low-level access to display. Creating an Image using Image class: Create an instance of an Image class by calling the createImage() method of the Image class. private Image img; img = Image.createImage(path); Displaying an Image on a Canvas

Once the image is created , it can be drawn on the Canvvs using drawImage() method of the Graphics class. Graphics.drawImage() drawImage() method takes four parameters. _ First parameter is the reference to the image that you want to display. _ second and third parameters indicate position of the image on Canvas. _ Fourth parameter specifies the portion of the image bounding box that is placed at the specified coordinate position. Example: graphics.drawImage(img,5,20,Graphics.HCENTER | Graphics.VCENTER) palces the center of the image at co-ordinate position (5,20). SOURCE CODE:
import java.util.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; class Consumption extends TimerTask { Javagochi javagochi; public Consumption (Javagochi javagochi) { this.javagochi = javagochi; } public void run () { javagochi.transform (-1 - javagochi.score/100); }} class KeyConfirmer extends TimerTask { Face face; public KeyConfirmer (Face face) { this.face = face; } public void run () {

face.keyConfirmed (); }} class Face extends Canvas { public static final String[] keys = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; Javagochi javagochi; Timer keyTimer; int keyMajor = -1; int keyMinor; char needed = 'a'; Face (Javagochi javagochi) { this.javagochi = javagochi; } public void paint (Graphics g) { g.setColor (255, 255, 255); g.fillRect (0, 0, getWidth (), getHeight ()); int height = Math.min (getHeight (), getWidth ()) / 2; int width = height * javagochi.weight / javagochi.IDEAL_WEIGHT; g.translate (getWidth () / 2, getHeight () / 2); g.setColor (255, 255, 255 - javagochi.getHappiness () * 25); g.fillArc (- width / 2, - height / 2, width, height, 0, 360); g.setColor (0, 0, 0); g.drawArc (- width / 2, - height / 2, width, height, 0, 360); g.drawString ("Score: "+javagochi.score, 0, -getHeight ()/2, Graphics.TOP|Graphics.HCENTER); String keySelect = "";

if (keyMajor != -1) { String all = keys [keyMajor]; keySelect = all.substring (0, keyMinor) + "[" + all.charAt (keyMinor) + "]" + all.substring (keyMinor+1); } g.drawString ("Feed: " + needed + " " + keySelect, 0, getHeight ()/2, Graphics.BOTTOM|Graphics.HCENTER); drawEye (g, - width / 6, - height / 5, height / 15 + 1); drawEye (g, width / 6, - height / 5, height / 15 + 1); switch (javagochi.getHappiness () / 3) { case 0: case 1: g.drawArc (-width/6, height/7, width/3, height/6, 0, 180); break; case 2: g.drawLine (-width/6, height/7, width/6, height/7); break; default: g.drawArc (-width/6, height/7, width/3, height/6, 0, -180); }} void drawEye (Graphics graphics, int x0, int y0, int w) { if (javagochi.isDead ()) { graphics.drawLine (x0 - w/2, y0, x0 + w/2, y0); graphics.drawLine (x0, y0 - w/2, x0, y0 + w/2); } else

graphics.fillArc (x0-w/2, y0-w/2, w, w, 0, 360); } public synchronized void keyPressed (int keyCode) { int index = keyCode - KEY_NUM2; if (keyTimer != null) keyTimer.cancel (); if (index < 0 || index > keys.length) keyMajor = -1; else { if (index != keyMajor) { keyMinor = 0; keyMajor = index; } else { keyMinor++; if (keyMinor >= keys [keyMajor].length ()) keyMinor = 0; } keyTimer = new Timer (); keyTimer.schedule (new KeyConfirmer (this), 500); } repaint (); } synchronized void keyConfirmed () { if (keyMajor != -1) { if (keys [keyMajor].charAt (keyMinor) == needed) { javagochi.score += javagochi.getHappiness (); if (!javagochi.isDead ()) needed = (char) ('a'

+ ((System.currentTimeMillis () / 10) % 26)); javagochi.transform (10); } keyMajor = -1; repaint (); } }} public class Javagochi extends MIDlet { static final int IDEAL_WEIGHT = 100; Display display; Face face = new Face (this); int weight = IDEAL_WEIGHT; Timer consumption; int score; public int getHappiness () { int happiness = 20 - (weight > IDEAL_WEIGHT ? 10 * weight / IDEAL_WEIGHT : 10 * IDEAL_WEIGHT / weight); if (happiness < 0) happiness = 0; else if (happiness > 10) happiness = 10; return happiness; } public boolean isDead () { return getHappiness () == 0; } public void transform (int amount) { if (!isDead ()) { weight += amount; face.repaint (); } }

public void startApp () { display = Display.getDisplay (this); display.setCurrent (face); consumption = new Timer (); consumption.scheduleAtFixedRate (new Consumption (this), 500, 500); } public void pauseApp () { consumption.cancel (); } public void destroyApp (boolean forced) { }}

OUTPUT:

RESULT: Thus the given exercise for animating an image using WML/J2ME had been completed successfully.

EXERCISE NO.9 DESIGN A FORM AIM: To Design a Form to store all the details of the customer. DESCRIPTION:
A form is a collection of instances of the Item interface. The TextBox class is a standalone UI element, while the TextField is an Item instance. Essentially, a textbox can be shown on a device screen without the need for a form, but a text field requires a form. An item is added to a form using the append(Item item) method, which simply tacks the added item to the bottom of the form and assigns it an index that represents its position in the form. The first added item is at index 0, the second at index 1, and so on. There are eight Item types that can be added to a form. 1. StringItem: A label that cannot be modified by the user. This item may contain a title and text, both of which may be null to allow it to act as a placeholder. The Form class provides a shortcut for adding a StringItem, without a title: append(String text) 2. DateField: Allows the user to enter date/time in one of three formats: DATE, TIME, or DATE_TIME. 3. TextField: Text is entered by using TextField. 4. ChoiceGroup: It contains one or more choices (elements), which must have a text part, an optional image part, and an optional font for the text part. 5. Spacer: Used for positioning UI elements by putting some space between them. This element is an invisible UI element and can be set to a particular size. 6. Gauge: A gauge is used to simulate a progress bar. However, this progress bar look can also be used in an interactive mode by the user. For example, if you wanted to show the user a volume control, a gauge would be used to show an interactive knob. 7. ImageItem: An item that holds an image!The Form class provides a shortcut method for adding an image: append(Image image). 8. CustomItem: CustomItem is an abstract class that allows the creation of subclasses that have their own appearances, their own interactivity, and their own notification mechanisms

SOURCE CODE: package com.j2me.part2; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Gauge; import javax.microedition.lcdui.Spacer; import javax.microedition.lcdui.ImageItem; import javax.microedition.lcdui.TextField; import javax.microedition.lcdui.DateField; import javax.microedition.lcdui.StringItem; import javax.microedition.lcdui.ChoiceGroup; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; public class FormExample extends MIDlet { private Form form; private Gauge gauge; private Spacer spacer; private ImageItem imageItem; private TextField txtField; private DateField dateField; private StringItem stringItem; private ChoiceGroup choiceGroup; public FormExample() { form = new Form("Your Details"); // a StringItem is not editable stringItem = new StringItem("Your Id: ", "WXP-890");

form.append(stringItem); // you can accept Date, Time or DateTime formats dateField = new DateField("Your DOB: ", DateField.DATE); form.append(dateField); // similar to using a TextBox txtField = new TextField("Your Name: ", "", 50, TextField.ANY); form.append(txtField); // similar to using a List choiceGroup = new ChoiceGroup( "Your meals: ", Choice.EXCLUSIVE, new String[] {"Veg", "Non-Veg"}, null); form.append(choiceGroup); // put some space between the items to segregate spacer = new Spacer(20, 20); form.append(spacer); // a gauge is used to show progress gauge = new Gauge("Step 1 of 3", false, 3, 1); form.append(gauge); // an image may not be found, // therefore the Exception must be handled // or ignored try { imageItem = new ImageItem( "Developed By: ", Image.createImage("/duke.gif"),

ImageItem.LAYOUT_DEFAULT, "DuKe"); form.append(imageItem); } catch(Exception e) {} }

public void startApp() { Display display = Display.getDisplay(this); display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }

OUTPUT:

RESULT:

Thus the given exercise for designing a Form using WML/J2ME had been completed successfully. EXERCISE NO: 10 SIMULATION OF AUTHENTICATION AND ENCRYPTION TECHNIQUE USED IN GSM AIM: To apply the Simulation of Authentication and encryption technique used in GSM. DESCRIPTION: Authentication - Whenever a MS requests access to a network, the network must authenticate the MS. Authentication verifies the identity and validity of the SIM card to the network and ensures that the subscriber is authorized access to the network. Encryption - In GSM, encryption refers to the process of creating authentication and ciphering cryptovariables using a special key and an encryption algorithm. Ciphering - Ciphering refers to the process of changing plaintext data into encrypted data using a special key and a special encryption algorithm. Transmissions between the MS and the BTS on the Um link are enciphered. Ki - The Ki is the individual subscriber authentication key. It is a 128-bit number that is paired with an IMSI when the SIM card is created. The Ki is only stored on the SIM card and at the Authentication Center (AuC). The Ki will never be transmitted across the network on any link. RAND - The RAND is a random 128-bit number that is generated by the AuC when the network requests to authenticate a subscriber. The RAND is used to generate the Signed Response (SRES) and Kc crypto-variables. Signed Response - The SRES is a 32-bit crypto-variable used in the authentication process. The MS is

challenged by being given the RAND by the network, the SRES is the expected correct response. The MS receives the RAND as a challenge and uses it to calculate the SRES. The SRES is passed up to the network to as a response to the challenge. A3 Algorithm - The A3 algorithm computes a 32-bit Signed Response (SRES). The Ki and RAND are inputted into the A3 algorithm and the result is the 32-bit SRES. The A3 algorithm resides on the SIM card and at the AuC. A8 Algorithm - The A8 algorithm computes a 64-bit ciphering key (Kc). The Ki and the RAND are inputted into the A8 algorithm and the result is the 64-bit Kc. The A8 algorithm resides on the ISM card and at the AuC. COMP128 - A keyed hash function that combines the A3 and A8 algorithms into a single function. The 128-bit Ki and 128-bit RAND are input into the COMP128 which generates a 32-bit SRES and a 54-bit Kc in a single function. COMP128 is weak because it can give away information about the Ki. Kc - The Kc is the 64-bit ciphering key that is used in the A5 encryption algorithm to encipher and decipher the data that is being transmitted on the Um interface. A5 - The A5 encryption algorithm is used to encipher and decipher the data that is being transmitted on the Um interface. The Kc and the plaintext data are inputted into the A5 algorithm and the output is enciphered data. The A5 algorithm is a function of the Mobile Equipment (ME) and not a function of the SIM card. The BTS also makes use of the A5 algorithm. There are three versions of the A5 algorithm: A5/1 - The current standard for U.S. and European networks. A5/1 is a stream cipher. A5/2 - The deliberately weakened version of A5/1 that is intended for export to non-western countries. A5/2 is a stream cipher. A5/3 - A newly developed algorithm not yet in full use. A5/3 is a block cipher.

Triplets - The RAND, SRES, and Kc together are known as the Triplets. The AuC will send these three crypto-variables to the requesting MSC/VLR so it can authenticate and encipher.

Result: Thus the given exercise to apply the Simulation of Authentication and encryption technique used in GSM had been completed successfully.

EXERCISE NO.11 BROWSING THE INTERNET USING MOBILE PHONE SIMULATOR AIM: To Browse the Internet using mobile phone Simulator. DESCRIPTION: Mobile simulator is a software application for a personal computer which creates a virtual machine version of a mobile device,[1] such as a mobile phone, iphone, other smartphone, or calculator, on the computer. This may sometimes also be termed an emulator. The mobile simulator allows the user to use features and run applications on the virtual mobile on their computer as though it was the actual mobile device.[1] Mobile simulators may be developed using programming languages such as Java and .NET.

RESULT: Thus the given exercise for browsing the Internet using mobile phone Simulator had been completed successfully.

Exercise No.10 STUDY OF GLOMOSIM SIMULATOR Aim: To study about the Glomosim simulator. Description: Global Mobile Information System Simulator (GloMoSim) is a network protocol simulation software that simulates wireless and wired network systems. GloMoSim is designed using the parallel discrete event simulation capability provided by Parsec, a parallel programming language. GloMoSim currently supports protocols for a purely wireless network. It uses the Parsec compiler to compile the simulation protocols.

Parsec
Parsec is a C-based simulation language, developed by the Parallel Computing Laboratory at UCLA, for sequential and parallel execution of discrete-event simulation models.

Commercial version
GloMoSim is academic research version available for academic use only. Commercial GloMoSim Based Product is QualNet. Result: Thus we had studied about the Glomosim Simulartor Successfully.

You might also like