mobile computing(2)

97
Mobile Computing PRACTICAL 1 AIM : - Study of Nokia Mobile Browser (NMB), Nokia Mobile Internet Toolkit (NMIT) and Nokia Mobile Gateway Simulator tools. Also WML and WML Script. Nokia Mobile Browser(NMB) Nokia Mobile Browser 4.0 SDK, and the Nokia Connecting People logo are trademarks or registered trademarks of Nokia Corporation. Other product and company names mentioned herein may be trademarks or trade names of their respective owners. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries. NMB is a mobile phone SDK that includes a mobile Internet browser for browsing both mobile Internet content (through a WAP connection) and local file content. It fully supports the content authoring features of Nokia Mobile Internet Toolkit 4.0 (NMIT) and can be used to display both xhtml and wml content, as well as Push messages. It also can be used standalone. Major differences between NMB 4.0 and NMB 3.1 include the following: NMB 4.0 is available as a separate download from Forum Nokia whereas NMB 3.1 was packaged with the NMIT 3.1 download. In essence, NMB 4.0 has been decoupled from NMIT 4.0 as part of the NMIT 4.0 redesign. NMB 4.0 can be launched as a standalone browser or used in conjunction with Nokia Mobile Internet Toolkit (NMIT), or both simultaneously. NMB 3.1 could be launched only from within NMIT 3.1. KALOL INSTITUTE OF TECHNOLOGY - 1 -

Upload: ankita-kapadia

Post on 06-Mar-2015

114 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile Computing(2)

Mobile Computing

PRACTICAL 1

AIM: - Study of Nokia Mobile Browser (NMB), Nokia Mobile Internet Toolkit (NMIT) and Nokia Mobile Gateway Simulator tools. Also WML and WML Script.

Nokia Mobile Browser(NMB)

Nokia Mobile Browser 4.0 SDK, and the Nokia Connecting People logo are trademarks or registered trademarks of Nokia Corporation. Other product and company names mentioned herein may be trademarks or trade names of their respective owners. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries.

NMB is a mobile phone SDK that includes a mobile Internet browser for browsing both mobile Internet content (through a WAP connection) and local file content. It fully supports the content authoring features of Nokia Mobile Internet Toolkit 4.0 (NMIT) and can be used to display both xhtml and wml content, as well as Push messages. It also can be used standalone.

Major differences between NMB 4.0 and NMB 3.1 include the following:

NMB 4.0 is available as a separate download from Forum Nokia whereas NMB 3.1 was packaged with the NMIT 3.1 download. In essence, NMB 4.0 has been decoupled from NMIT 4.0 as part of the NMIT 4.0 redesign.

NMB 4.0 can be launched as a standalone browser or used in conjunction with Nokia Mobile Internet Toolkit (NMIT), or both simultaneously.NMB 3.1 could be launched only from within NMIT 3.1.

You can launch multiple instances of NMB 4.0 simultaneously and use these independently, and you can display NMIT 4.0 content on all running instances of NMB 4.0Only one instance of NMB 3.1 was supported through NMIT 3.1.

NMB 4.0 now includes diagnostic views through its Tools>Diagnostics menu. These views are displayed in a separate window adjoining the NMB 4.0window.Diagnostic views for NMB 3.1 were available through the NMIT 3.1 "tab views" interface.

The Nokia Mobile Browser 4.0 SDK is designed for use by mobile Internet content developers who wish to display mobile Internet content on a mobile handset emulator. This content may be local file content, content accessed over the Internet, or content developed within Nokia Mobile Internet Toolkit (NMIT) and pushed to NMB directly from within the NMIT environment.

Typographical Conventions

The following typographical conventions are used in this guide:

KALOL INSTITUTE OF TECHNOLOGY- 1 -

Page 2: Mobile Computing(2)

Mobile Computing

Resources

Other Recommended Documents:

o Nokia Mobile Internet Toolkit 4.0 User's Guide o Nokia WAP Gateway Simulator User's Guide o WAP 2.0 specifications available at Open Mobile Alliance. o Content authoring papers and other information at Forum Nokia.

Nokia Mobile Browser 4.0 SDK (NMB) :

Using NMB, content developers can display any mobile Internet content developed using Nokia Mobile Internet Toolkit 4.0 (NMIT), as well as local file content and content resident on Internet servers and accessed through a WAP connection. WAP connections may be made through either a WAP gateway server or through Nokia's WAP Gateway Simulator (NWGS).

KALOL INSTITUTE OF TECHNOLOGY- 2 -

Page 3: Mobile Computing(2)

Mobile Computing

NMB can be used in a standalone fashion to load local or mobile Internet content. It can handle all content types capable of being created within NMIT except Multimedia (MMS) messages.

You can load mobile Internet content in any of the following ways:

Choose the Load URL menu item (or popup menu) to load content from the Internet. For this type of content, NMB must be configured to use either an external WAP gateway or Nokia WAP Gateway Simulator (NWGS). If using NWGS, NWGS must be running before choosing Load URL. The section titled Configuring NMB describes NMB configuration.

By opening a wml, xhtml, si, sl, co, gif, or wbmp file on the local network using the Open File menu item (or popup menu).

By loading content from NMIT. NMIT enables direct display of content authored using its content development editors. The previewing mechanism is either a button within the editing window or a menu selection from the application menu bar. NMB can display WML, XHTML, MMS, or Push (si, sl, co, mp) content.

Additional important features of NMB include the following:

You can establish secure connections to an external WAP gateway using the WTLS protocol, levels 1, 2, or 3.

You can use WIM security features (Certificates, PINs, and Keys) and display information about these in NMB's WIM view.

You can receive unsolicited Push messages from an external WAP gateway. NMB listens for these on a specified port.

Content Type Support

NMB is capable of displaying the following content types.

Content Types Supported Through Both File>Open and the CLIKALOL INSTITUTE OF TECHNOLOGY

- 3 -

Page 4: Mobile Computing(2)

Mobile Computing

The following table lists the content types that may be opened using either the File>Open menu item or specified on the command line through the CLI interface:

WAP Protocol Support

The Nokia Mobile Browser 4.0 SDK supports the WAP June 2000 (or WAP Version 1.2.1) specifications. These may be found at the WAP Forum site at the page titled the June 2000 (WAP 1.2.1) conformance release. Supported content includes WML, WML Script, and XHTML, as well as WBMP and GIF image formats.

WAP-Specific Functions Supported

GPS and GSM location information WIM and WTLS security functions Push message reception

Font Support

When displaying XHTML content that specifies the CSS font family property, the Nokia Mobile Browser Simulator displays the content in fonts based on the following rules, which correspond to standard CSS recommendations:

If the content specifies no font family, NMB uses the Arial font family, which is the default.

If the content specifies a generic font mapping, NMB translates that mapping to an installed True Type font as follows:

KALOL INSTITUTE OF TECHNOLOGY- 4 -

Page 5: Mobile Computing(2)

Mobile Computing

.

Keyboard Shortcuts

Use the keyboard keys and the numeric keypad keys (if your computer has one) to enter characters in input boxes within the NMB display. Additionally, you may use some of these keys singly or in combination instead of using the mouse to press keys on the NMB display. The table in this section lists keyboard and numeric keypad keys that can substitute for mouse clicks. These are called keyboard shortcuts.

A keyboard shortcut involving more than one key is performed by holding down the key preceding the plus sign (+) and then pressing the key following the plus sign. In effect, pressing two keys simultaneously. Some combinations use three keys: in this case, hold down the first two and then press the third.

Note that because notebook computers usually do not have a number pad, equivalent shortcuts to those using the number pad (the NumPad shortcuts) are provided; these are three-key combinations beginning with the characters CTRL+ALT.

KALOL INSTITUTE OF TECHNOLOGY- 5 -

Page 6: Mobile Computing(2)

Mobile Computing

Nokia Mobile Internet Toolkit

Displaying Push Messages From NMIT Editors

NMB supports the display of Push messages created in NMIT editors and pushed to NMB from within the editors. These Push messages are encoded by NMIT and written to a file. NMIT then sends a load request to NMB, which then loads the file specified by NMIT.

Note, however, that NMB is also capable of receiving Push messages sent by a Push Initiator server over the network (rather than through NMIT), and in this case NMB may be configured to use either NWGS or an external WAP gateway for this connection.

The advantage of using NMIT to display Push messages on NMB is that this facilitates the design and testing of Push messages without having to create a Push Initiator application.

If, however, you are developing a complete Push application framework, you will generally first use the NMIT Push features to develop the initial Push message and then, when you are satisfied with its display, develop a Push Initiator application that creates and pushes such messages.

NMB supports the display of the four types of Push messages: Service Indication (SI), Service Loading (SL), Cache Operation (CO), and Multipart (MP). Use NMB's Push diagnostics view in conjunction with your development efforts, and for SL, CO, and the MP Push types also use NMB's Cache diagnostics view. The procedure shown here for creating and displaying a Push message uses SI as the example content type. The browser application enables the display of content requested by the user through HTTP requests or (only when NWGS is configured) through local file requests.

Use the following procedure to display a Push message from NMIT on NMB:

LaunchNMIT.(Start>Programs>Nokia>Nokia Mobile Internet Toolkit)Open the SI editor by either (1) opening an existing SI file (Fille>Open) or (2) creating a new SI file (File>New and then the Push tab and then Service Indication).

Within the editor, enter a text message in the Text Message field and then a URI in the href field. The URI may be either an Internet URL in the form http://wap.yahoo.com or a file URL in the for file://C:\Myfiles\MyMessage.xxx. In either case, NMB will need to be configured to use NWGS for a gateway connection.

LaunchNWGS(Start>Programs>Nokia>Nokia WAP Gateway Simulator) and configure it to use an HTTP proxy server if necessary.

KALOL INSTITUTE OF TECHNOLOGY- 6 -

Page 7: Mobile Computing(2)

Mobile Computing

Within NMIT, launch NMB by first choosing Tools>Active SDK Control Panel and then choosing the green launch button adjacent to NMB, which should be listed in the panel.

Within NMIT, choose the Push button in the SI editor.The message isreceived by NMB. This is indicated by noting the symbol on the NMB title line as shown below.

Choose NMB's Options button. NMB displays the Push Inbox and Main Menu options, as shown below.

.

KALOL INSTITUTE OF TECHNOLOGY- 7 -

Page 8: Mobile Computing(2)

Mobile Computing

NMB's Push Inbox displays all Push messages that you have not yet deleted. In the figure above, the Inbox contains only the message that we have just pushed. Because this is an SI message, the text content included in the message "Check out the weather!" is displayed. At this point, the message has not been processed by NMB. You can tell this because the mail icon remains an unopened envelope and is still yellow in color. (The icon for a processed message is a white opened envelope.) If multiple messages were present in the Inbox, you would need to navigate to and select the one you wished to open. In this case, there being only one, it is already selected.

Choose Options. As shown below, the available options are the following:

o Retrieve the content specified by the URL included in the SI message.

o View Details about the message (shown below). o Erase the message.

Choose Retrieve to load the URL specified in the message. In this case, as is shown below, the URL is an image, a WBMP file.

Choose Options and then Push Inbox to open the Inbox once again (remember NMB's browser was launched to fetch the URL). Choose Options again but this time choose Details to display message details as shown below:

KALOL INSTITUTE OF TECHNOLOGY- 8 -

Page 9: Mobile Computing(2)

Mobile Computing

Message details include four items: o Title shows the text content. o Address shows the URL of the content to be retrieved. o Created shows the date and time of message creation. o Expires shows the date and time the message expires at which time

it will be deleted.

NMB Settings

Choose NMB's Tools>Settings menu to display the Settings dialog consisting of the following eight tab pages:

Connection Settings

Choose Tools>Settings and then the Connection tab to display the following settings dialog:

KALOL INSTITUTE OF TECHNOLOGY- 9 -

Page 10: Mobile Computing(2)

Mobile Computing

You may choose either the default or a custom setting when configuring an NMB connection to a WAP gateway:

Appearance Settings

Choose Tools>Settings and then the Appearance tab to display the following settings dialog:

KALOL INSTITUTE OF TECHNOLOGY- 10 -

Page 11: Mobile Computing(2)

Mobile Computing

Appearance settings enable you to configure the NMB window behavior with respect to display screen size:

KALOL INSTITUTE OF TECHNOLOGY- 11 -

Page 12: Mobile Computing(2)

Mobile Computing

Browser Settings

Choose Tools>Settings and then the Browser tab to display the following settings dialog:

Browser settings enable you to configure NMB browser behavior:

Response Settings

Choose Tools>Settings and then the Response tab to display the following settings dialog:

KALOL INSTITUTE OF TECHNOLOGY- 12 -

Page 13: Mobile Computing(2)

Mobile Computing

Response settings enable you to configure the NMB browser to display a warning message when receiving content exceeding a specified size:

Nokia Mobile Gateway Simulator tools:

Configuring NMB

After installing NMB, you can configure its settings using the Settings dialogs accessible through the Tools>Settings menu item. Settings are described in the chapter titled NMB Settings.

Configure NMB to use either an external WAP Gateway (whose IP address you must know) or the Nokia WAP Gateway Simulator (NWGS). Do this by choosing NMB's Tools>Settings menu item and then the Connections tab. By default, NMB is configured to use NWGS whose IP address is 127.0.0.1. You can use either NWGS or an external WAP gateway.

If you are using NWGS as the WAP Gateway, launch NWGS from the Windows Start menu as follows:

Start>Programs>Nokia>WAP Gateway Simulator. NWGS must be running before you can browse mobile Internet content. (You can download NWGS from Forum Nokia.) Configure NWGS for a proxy server if you access the Internet through a proxy server. Within NWGS, use the Settings>Proxy menu item to specify the proxy server.

To further explain, when configured to use an external gateway, no proxy is needed because Internet requests go out over the WAP protocol, thus bypassing any corporate proxy server (typically an HTTP proxy server). On the other hand, when configured to use NWGS, which runs on the local machine, Internet requests sent from NWGS are going out over the HTTP protocol and thus pass through any corporate proxy server.

Using NMB

When using NMB standalone,use the File>Open menu item to display browsable content. (See the section titled Content Type Support to learn which content NMB can display.)

You can browse both mobile Internet and file content. To browse mobile Internet content, NMB must be configured to use a WAP gateway or NWGS: in the latter case, NWGS must also be and running when you choose the File>Open menu option.

KALOL INSTITUTE OF TECHNOLOGY- 13 -

Page 14: Mobile Computing(2)

Mobile Computing

Displaying Push Messages From a File

Use the following procedure to display Push message files on NMB:

Launch NMB and choose File>Open File. In the Open File dialog, navigate to and select a Push file of type .si, .sic, .sl, .slc, .co, .coc, or .mpc. Note that only the .si, .sic, and .mpc types will display in NMB's Push Inbox.

The message is received by NMB. This is indicated by noting the symbol on the NMB title line shown below.

Refer to the section titled Displaying Push Messages From NMIT Editors, starting at step 6, for a description of using the Push Inbox to retrieve, view details, and erase the Push message.

KALOL INSTITUTE OF TECHNOLOGY- 14 -

Page 15: Mobile Computing(2)

Mobile Computing

WML&WML SCRIPT:

History

The History view displays the navigational history of the current NMB browser session, with the most recent location displayed last at the bottom of the history list.

The following figure shows the History view in its collapsed state. Summary details are displayed on two lines, the second showing the number of items currently on the stack, as shown in the following figure:

The following figure shows the above History view after expansion.

Note the following with respect to the expanded History view:

Navigational history is displayed showing one location per line, with the most recent location displayed last at the bottom of the list.

The location currently displayed on NMB is shown in the History view in bold type.

In the case of XHTML-based content, whether loaded from the network or from file, navigational history always grows larger as new locations are loaded. However, for WML content, this is not always true. Some WML decks, in particular those wherein variables are defined, use the newcontext attribute within <card> elements. This causes a resetting (clearing) of both variables and history. If this should happen, the History view will show the text "Removed" followed by the location of the WML content that caused the resetting of navigational history.

Choosing the drop-down arrow adjacent to the History view title displays the Go Back command. Use this button to navigate to the previous location. You can use this button successively to navigate back to the earliest location.

KALOL INSTITUTE OF TECHNOLOGY- 15 -

Page 16: Mobile Computing(2)

Mobile Computing

Telephony Settings

Choose Tools>Settings and then the Telephony tab to display the following settings dialog:

Use the Telephony tab to configure NMB for testing the three Public WTAI functions described in the WAP WTAI specification. WTAI (Wireless Telephony Application Interface) specifies an application interface between WML and WMLScript and the built-in telephony functions of a mobile device. The WTAI functions may be invoked by (1) a WMLScript function call or (2) by an href value specified within an <a> element using a dedicated WTAI URI encoding scheme. The following lists the three functions and gives the syntax for both methods of invocation

KALOL INSTITUTE OF TECHNOLOGY- 16 -

Page 17: Mobile Computing(2)

Mobile Computing

Because NMB does not possess real telephony functions, it cannot actually execute any of the above three functions. Instead, NMB intercepts a programmatic call to any of these three functions. You use the Telephony settings in NMB to specify what action NMB should take after interception: (1) return a previously specified value or (2) display a dialog in which you pick the return value. This enables you to test the error handling code in your application.

For each of the three WML Script functions, you can specify return values as follows:

WMLScript versus URI Methods of Invoking WTAI Function Calls

KALOL INSTITUTE OF TECHNOLOGY- 17 -

Page 18: Mobile Computing(2)

Mobile Computing

PRACTICAL 2

AIM: - The Information Master Application.

The Information Master application deals with providing information about movies and the weather to the client. It’s made up of three WML files, one WMLS file and one graphic file. The script file has just one function for generating the random numbers for the display of maximum and minimum temperatures on the screen.

Application Structure :

The case study discussed here contains the following files :Information.wml Movie.wml Weather.wml Weather.wmls Sun.icoThe first three files are the WML application files; the fourth is the script file that will be used by Weather.wml file, Sun.ico is an image file used to display the image of sun on the browser screen by the Weather.wml code file. 

Application Work Flow  : The application opens a menu with two options : Movie and Weather, If the user clicks Movie, the Movie.wml file, which display the name of movies and show timing, appears. If the user clicks Weather, the Weather.wml file, which display the maximum and minimum temperatures of various cities on the screen, appears. The temperatures are generated by using Lang.rand() in the script file and by Weather.wml to display them on-screen. 

KALOL INSTITUTE OF TECHNOLOGY- 18 -

Page 19: Mobile Computing(2)

Mobile Computing

Theory:-

WML Tags:-

Card: This tag helps the user to create a card which acts as a canvas on which the user works for the application creation.

P: This tag helps the user to write in the canvas of the card that the user is using for creating the application.

Anchor: This tag helps the user to create a link in the application with the other card or other WML file.

Do: This tag helps the user to create the options in the available options tab of the simulator and creates a new link.

Go: This tag helps the user to pass on control to the valid link after the anchor tag has been invoked.

Img: The image tag allows the user to add an image on the Canvas i.e. the card he is working on the application.

Functions:-

Extern keyword: By making a function extern we make it accessible globally.

Lang.Random( range) : Generates a random integer number. The range of the number is from zero to the number defined in the function’s argument.

Dialogs.Alert( String ) : It is used to display warning message to user.

KALOL INSTITUTE OF TECHNOLOGY- 19 -

Page 20: Mobile Computing(2)

Mobile Computing

Program:

<?wml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN"

"http://www.wapforum.org/DTD/wml13.dtd"><wml>

<card id="card1" title="Information"><p>

Please Select any One Topic<br/><anchor title="Movies"><go href="#card2"/>Movies</anchor><br/><anchor title="Weather"><go href="#card3"/>Weather</anchor></p></card>

<card id="card2" title="Movies"><p>

This is the Movies Card<br/> The Movies Are as follows:<br/> Rock On : 12:00,3:00,6:00,9:00<br/>

Hancock: <br/>1:00,4:00,7:00</p><do type="accept" label="Back"> <go href="#card1"/></do></card>

<card id="card3" title="Weather"><do type="accept" label="go">

<go href="weather.wmls#Gettemp()"/> </do><p>

This is the Weather Card<img src="C:\Program Files\JavaWebStart\JavaCup.ico” alt=”kit”></img>

</p></card>

</wml>

Weather.wmls

extern function Gettemp(){

var a;var b;

a=Lang.random(100);b=Lang.random(50);

KALOL INSTITUTE OF TECHNOLOGY- 20 -

Page 21: Mobile Computing(2)

Mobile Computing

while(a<b){

a=Lang.random(100);b=Lang.random(50);

} Dialogs.alert("Maximum Temp=" + a + "Minimum Temp=" + b);}

Output:

KALOL INSTITUTE OF TECHNOLOGY- 21 -

Page 22: Mobile Computing(2)

Mobile Computing

PRACTICAL 3

AIM:- The Restaurant Application.

This application starts with a menu from which the user can select different items to order from restaurant. After the user selects the items, the bill is generated accordingly. 

Application StructureThe application is made up of following files :ResScript.wmls – The scripting fileRestaurant.wml – The main menu file to select the categorySouth.wml – Link file to select items of the South India dishes categorySoft.wml – Link file to select items of Soft Drinks categorySnacks.wml – Link file to select items of Snacks category

Application Work FlowThe main file is Restaurant.wml , which shows three items :South Indian (South.wml)Soft Drink (Soft.wml)Snacks (Snacks.wml)

After you click a particular item, the system calls the corresponding WML file and shows the item related to that category.

THEORY:-

WML Tags:-

Card : This tag helps the user to create a card which acts as an canvas on which the user works for the application creation.

P : This tag helps the user to write in the canvas of the card that the user is using for creating the application.

KALOL INSTITUTE OF TECHNOLOGY- 22 -

Page 23: Mobile Computing(2)

Mobile Computing

Anchor : This tag helps the user to create a link in the application with the other card or other WML file.

Do : This tag helps the user to create the options in the available options tab of the simulator and creates a new link.

Go : This tag helps the user to pass on control to the valid link after the anchor tag has been invoked.

Input : This tag helps the user to input words in the sdk.

Option : This tag allows the user to add the check boxes into the application

Optgroup : This tag allows the user to add the check boxes in the form of a group to the application.

Program :

Restaurant.wml

<?xml version="1.0" ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>

<card id="main" title="BIT Restaurant"><p align="center"> <b> <u> MENU </u> </b> </p><p> <anchor title="Go for Snack">

<go href="snack.wml"/> Snack </anchor> </p><p> <anchor title="Go for Softdrink">

<go href="soft.wml"/> Soft Drink </anchor> </p><p> <anchor title="Go for South Indian">

<go href="south.wml"/> South Indian </anchor> </p> <p> <anchor title="Bill.."> <go href="bill.wml"/> Bill... </anchor>

</p>

<p> <input name="bill" /> </p></card> </wml>

KALOL INSTITUTE OF TECHNOLOGY- 23 -

Page 24: Mobile Computing(2)

Mobile Computing

Soft.wml

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <card id="soft" title="Soft Drinks">

<!--<p> Drink-1...10/- </p><p> Drink-2...15/- </p><p> Drink-3...25/- </p> -->

<p><do type="accept" label="Go"> <go href="#bill"/> </do>

<select name="soft" value="3" multiple="true" title="Drink"> <optgroup> <option onpick="bill.wmls#bill(10)" value="10">Drink-1...10</option> <option onpick="bill.wmls#bill(15)" value="15">Drink-2...15</option> <option onpick="bill.wmls#bill(25)" value="25">Drink-3...25</option> </optgroup>

</select>

<anchor title="Go Back"> <go href="/restaurant.wml"/> Back </anchor>

</p>

</card>

<card id="bill" title="Bill.."><p>Your bill amount for Soft Drink is: $(soft) </p></card></wml>

KALOL INSTITUTE OF TECHNOLOGY- 24 -

Page 25: Mobile Computing(2)

Mobile Computing

Snack.wml

<?xml version="1.0" ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml>

<card id="snack" title="Snack"><!-- <p> Item-1.....5/- </p>

<p> Item-2...15/- </p><p> Item-3...25/- </p> -->

<p><do type="accept" label="Go"> <go href="#bill"/> </do>

<select name="snack" value="3" multiple="true" title="Drink"> <optgroup> <option onpick="#bill" value="10">Snack-1...10</option> <option onpick="#bill" value="15">Snack-2...15</option> <option onpick="#bill" value="25">Snack-3...25</option> </optgroup>

</select>

</p></card>

<card id="bill" title="Bill.."><p>Your bill amount of Snack is: $(snack) </p></card>

</wml>

KALOL INSTITUTE OF TECHNOLOGY- 25 -

Page 26: Mobile Computing(2)

Mobile Computing

South.wml

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"> <wml> <card id="south" title="South Indian">

<p> Item-1...35/- <do type="accept" label="Item-1"><go href="bill.wmls#bill(35)"/></do>

</p><p> Item-2...15/-

<!-- <do type="accept" label="Item-2"><go href="bill.wmls#bill(15)"/></do> -->

</p><p> Item-3...25/-

<!-- <do type="accept" label="Item-3"><go href="bill.wmls#bill(25)"/></do> -->

</p></card> </wml>

Bill.wml

<?xml version="1.0" ?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">

<wml> <card id="main" title="Bill.."><p> Your bill amount is: </p></card></wml>

Bill.wmlsextern function bill(x) { // enter your function body herevar y = WMLBrowser.getVar("bill");Lang.parseInt(x) ;y = y + x;WMLBrowser.setVar("bill", y); Dialogs.alert("Bill is :" + y);

KALOL INSTITUTE OF TECHNOLOGY- 26 -

Page 27: Mobile Computing(2)

Mobile Computing

Output :

KALOL INSTITUTE OF TECHNOLOGY- 27 -

Page 28: Mobile Computing(2)

Mobile Computing

KALOL INSTITUTE OF TECHNOLOGY- 28 -

Page 29: Mobile Computing(2)

Mobile Computing

PRACTICAL: 4

AIM: - To do list: Creation of child process with error handling capacity

(spawn, throw, catch) once can use "fieldset" to group the simillar elements should provide information regarding deck and its access

control information (head) "link" option, "postfield" option for passing information to

http server "receive" from child process "table" for tabular structure "timer" to perform some task after some period

Theory:-

(i) Creation of child process with error handling capacity (spawn, throw, catch)

Spawn:

The <spawn> element declares a spawn task, indicating the creation of a child context and invocation of a URL in that child context. If the URL names a WML card or deck, the card is displayed, and the URL becomes the basis for a new history stack in the child context.

When the child context is exited via the exit task, an onexit intrinsic event occurs. The on exit event can be handled with the onexit attribute or by embedding an <onevent>inside the <spawn> element. A spawn task can initialize the child context's variables withthe <setvar> element, parameters returned from the child context are bound to variableswith <receive> elements, and exceptions that occur in child contexts can be caught withthe <catch> element.

The spawn element may also contain one or more <postfield> elements. Theseelements specify information to be submitted to the origin server during the request.

Syntax:

<spawn href="/child" onexit="/continue"><setvar name="Name" value="Joe"/></spawn>

The <spawn> element creates a new child context, and invokes the “/child” URL in thisnew context. The child context initializes with the variable “Name” which evaluates to“Joe”. When the child context exits, the onexit event occurs, resulting in a <go> task to the “/continue” URL.

KALOL INSTITUTE OF TECHNOLOGY- 29 -

Page 30: Mobile Computing(2)

Mobile Computing

Attributes:

href Required. Specifies the destination URL. The URL of the card to display.

onexit The onexit event occurs when the child context is exited with an exit task.

sendreferer true | falseSpecifies whether the device should include the deck URL in the URL request. Specifying sendreferer="true" causes the device to set the HTTP_REFERER header to the relative URL of the requesting deck. If you want to restrict access to trusted services, decks that request specified URLs must set this option to TRUE.

method get | postSpecifies the HTTP submission method. Specifying method="post" causes the Openwave Mobile Access Gateway Server to transcode variable data to the character set specified by the HTTP headersdefined in your application. You should perform this transcoding if non-ASCII characters (specifically UTF-8) may exist in the data being passed

Acceptcharset Specifies the character encodings that your application can handle. The device uses this attribute to transcode data specified by the postfield element. The Openwave Mobile Access Gateway Server assumes UTF-8 as the default encoding (of which US-ASCII is a subset), so WML services in the United States, Canada, or Australia do not need to use this attribute. You can also omit this attribute if you specify your character set(s) in the HTTP response header. Note that the accept-charset attribute overrides any character encodings you specify in the HTTP header.The syntax for this attribute is a comma- or space-delimited list of IANA character sets. For example, accept-charset="UTF-8,US-ASCII, ISO-8859-1".

Throw:

KALOL INSTITUTE OF TECHNOLOGY- 30 -

Page 31: Mobile Computing(2)

Mobile Computing

The <throw> element declares a throw task, indicating that an exception should be raised. Values may be sent to the exception handler with <send> elements included in the throw. Throwing an exception terminates the current context and causes the context to be destroyed, including any variable and history state contained in the context. If the parent context does not contain an exception handler (a <catch> element) that matches this exception, or a </catch> element, the parent context is terminated and the exception is re-thrown to that context’s parent. This operation repeats until an exception handler is found or all parent contexts have been terminated. In the case where all contexts are terminated, the Browser performs a reset to a predictable state. Typically, this clears the history stack and displays the home deck.

For example, the following throws an exception with the name "user input error". In addition, a parameter block is included specifying more information about the error.

Syntax:

<throw name="user input error"><send value="Bad numeric value"/></throw>

Attributes:

Name Required. Specifies the name of the exception. This name is used to find the correct handler for the exception. The name attribute value is case sensitive.

Catch :

The <catch> element specifies an exception handler that can process an exception passed by a throw task. Parameters sent with the exception are received with the<receive> element.An onthrow event occurs when the exception is caught and can be bound to a task. The onthrow event can be handled with the onthrow attribute or by embedding an <onevent> inside the <catch> element.

A <spawn> element cannot contain more than one <catch> element with the same name.

Syntax:

<catch name="error#1" onthrow="/displayError"><receive name="Msg"/></catch>

Attributes:

KALOL INSTITUTE OF TECHNOLOGY- 31 -

Page 32: Mobile Computing(2)

Mobile Computing

name Specifies the name of the exception. If the name attribute is missing, the <catch> element will handle any exception.

(ii) One can use "fieldset" to group the simillar elements:

The <fieldset> element allows you to group multiple text or input items within a card.Specifying one or more <fieldset> elements lets you control how the device presentscard content in order to simplify user navigation.

Syntax:

<fieldset title="label">content</fieldset>

where content represents the items to group together and consists of one or more of thefollowing elements

You can specify any of the following elements in a <fieldset> group:• <fieldset> (a nested <fieldset>)• <input> • <select>

text : You can also specify formatted text in a <fieldset> group. The device uses this text in different ways depending on the elements you specify(for example, to prompt the user for input or describe various options).

Devices display these elements in the order in which you specify them.

Attributes:

title Specifies a brief label for the <fieldset> group. Some devices use thelabel as a title when displaying the <fieldset> content. Others might use it as a label for a user interface mechanism that lets the user navigate to the <fieldset> content. For example, if a device cannot display all card content on one screen and ordered="true”, the Mobile Browser uses the title to identify this group of items on a summary-level menu.

(iii) Should provide information regarding deck and its access control information (head):

Every WML deck must contain three things: the document prologue, an element that designates the WML deck, and at least one card. You've already looked at the document prologue previously in this chapter. Now let's focus on the elements that designate the WML deck, specifically the WML elements. The WML element is a simple, but powerful element. The WML element consists of no attributes, always follows directly after the document prologue, and is always the last tag element of a WML file.

<head>

KALOL INSTITUTE OF TECHNOLOGY- 32 -

Page 33: Mobile Computing(2)

Mobile Computing

The <head> element specifies information about the deck as a whole, including metadataand access control information.

Syntax:

<head> content</head>

where content represents deck-level header information:You can optionally specify either of the following elements in a WML deck header:• <access>—one only • <meta>—one or more

The following example illustrates how to specify the maximum age of a deck. The WMLdefinition includes a <meta> statement that uses cache-control within the <head> element:

<wml><head>

<meta http-equiv="Cache-Control" content="max-age=3600"forua=”true”/>

</head><card>

...</card><card>

...</card></wml> (iv) "link" option, "postfield" option for passing information to http server

<link>

The <link> element specifies a relationship between the containing deck and anotherdocument. This element must exist inside the <head> element.

Syntax:

<wml><head>

<link href="/next" rel="next"/></head>

</wml>

Attributes:

KALOL INSTITUTE OF TECHNOLOGY- 33 -

Page 34: Mobile Computing(2)

Mobile Computing

href Required. Specifies the location of the document being linked to.

rel Required. Specifies the relationship between this deck and thedocument referenced by the href attribute.

sendreferer true | false Specifies whether the device should include the deck URL in the URLrequest. Specifying sendreferer="true" causes the device to set the HTTP_REFERER header to the relative URL of the requesting deck. If you want to restrict access to trusted services, decks that request specified URLs must set this option to TRUE.

<postfield>

The <postfield> element defines name/value pairs that are passed to the HTTP serverreceiving the <go> request.

Syntax:

<postfield name="name" value="value"/>

Attributes:

name Required. A label that identifies the field.

Value Required. A string specifying the default value for the variable specified by the value attribute.

(v) "receive" from child process

<receive>

The <receive> element is used to receive data sent from a child context. A <receive> element without a name attribute causes the value in the parameter block to be ignored. When receiving a parameter block, <receive> elements assign a corresponding variable to each value in that parameter block. If there are insufficient values in the parameter block, each additional <receive> should be treated as if the parameter block contained an empty string in that position.

Syntax:

<receive name="X"/>

Attributes:

KALOL INSTITUTE OF TECHNOLOGY- 34 -

Page 35: Mobile Computing(2)

Mobile Computing

name Specifies the variable name. It is an error if the name attribute value is not a legal WML variable name.

(vi) "table" for tabular structure

<table>The <table> element allows you to specify columnar format. WML tables are similar to HTML tables. It is used together with the <tr> and <td> elements to create sets of aligned columns of text and images in a card. Nesting of <table> elements is not allowed. The <table> elements determine the structure of the columns. When defining a table, you have to declare the number of columns, followed by some content. The content can include empty rows and columns. Whilst the elements separate content into columns, they do not specify column or intercolumn widths.

Syntax:

<table title="name" align="left|right|center" columns="numberof columns">...row and data declarations</table>

Attributes:

Align left | right | centerSpecifies text alignment relative to the column. If you do not specify the align attribute, the text is automatically left-aligned.

Title Specifies a label for the table.

Columns Required. Specifies the number of columns for the row set. Specifying a zero value for this attribute is not allowed.

Example:

KALOL INSTITUTE OF TECHNOLOGY- 35 -

Page 36: Mobile Computing(2)

Mobile Computing

<wml><card>

<p> Prague <img localsrc="sun" alt="" src=""/> </p><p mode="nowrap">

<table columns="2"><tr><td><i>High</i></td><td><i>Low</i></td></tr><tr><td>53</td><td>42</td></tr>

</table> Today: Mostly sunny and cool.<br/>Tonight: Cold with chance of light rain.

</p></card>

</wml>

(vii) "timer" to perform some task after some period

<timer>

The <timer> element provides a method for invoking a task automatically after someperiod of user inactivity. Any task or user action that activates the card starts the timer, and executing any task element stops it. You can only associate one task for each timer, and you can only define one timer for each card.

Syntax:

<timer name="variable" value="value"/>

Attributes:

name The name of the variable in which the device stores the timer value. If the variable has no value when the timer is initialized, the device sets it to the value specified for the default attribute. The device sets this variable to either the current timer value when the user exits the card or 0 if the timer expires.

value A string specifying the value for the variable specified by the key attribute. You must specify <timer> values in units of 1/10 seconds—so, for example, a value of 100 equals 10 seconds. Specifying a value of 0 disables the timer.If the name attribute already has a value when the timer is initialized, the device ignores the default attribute. If the name attribute does not already have a value, the device sets it to the value specified by the value attribute.

The following example illustrates how a timer can initialize and reuse a counter. The device resets the timer to the value of the time variable each time the user navigates to the

KALOL INSTITUTE OF TECHNOLOGY- 36 -

Page 37: Mobile Computing(2)

Mobile Computing

card. If time has no value, the device sets the timer to 5 seconds. When the timer expires, the device automatically displays the second card in the deck.

<wml><card ontimer="#card2">

<timer name="time" value="50"/><p> Hello, Unwired World! </p>

</card><card id="card2">

...</card>

</wml>

PRACTICAL 5

KALOL INSTITUTE OF TECHNOLOGY- 37 -

Page 38: Mobile Computing(2)

Mobile Computing

AIM: - Study of Open wave SDK Toolkit and write a WML application to print the text in boldface letters, italic, underline, small and big size.

Theory:-

WML Tags:-

Card: This tag helps the user to create a card which acts as a canvas on which the user works for the application creation.

P: This tag helps the user to write in the canvas of the card that the user is using for creating the application.

Br: This tag is used to end the line.

B: This tag enables the text to be bold.

I: This tag enables the text to be italics.

U: This tag enables the text to be underlined.

Small: This tag enables the text to be represented in small fonts than normal.

Big: This tag enables the text to be represented in large fonts than normal.Program:

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//OPENWAVE.COM//DTD WML 1.3//EN" "http://www.openwave.com/dtd/wml13.dtd">

<!-- WML file created by the Openwave SDK -->

<wml> <card id="s1" title="Formatted Text">

<p>

<b>Engineering Branches</b><br/>

<i>Computer</i><br/>

<u>Electronics</u><br/>

<small>Mechanical</small><br/><big>Electrical</big><br/></p>

KALOL INSTITUTE OF TECHNOLOGY- 38 -

Page 39: Mobile Computing(2)

Mobile Computing

</card></wml>

Output:

Open Wave SDK Toolkit

The Openwave SDK 5.1 is an integrated development environment that contains everything you need to create wireless services. Its key components are tools for authoring, device simulation, and debugging.

 Authoring

The Openwave SDK includes a built-in editor for writing wireless content. The editor supports the following file types:

HDML 3.0 WML 1.3 WMLScript 1.2 XHTML Mobile Profile Editing features include cut, copy, paste, and multilevel undo/redo, to help you

produce and manipulate content quickly and easily. You can also customize the

KALOL INSTITUTE OF TECHNOLOGY- 39 -

Page 40: Mobile Computing(2)

Mobile Computing

code view by changing the highlighting options associated with tags, attributes, comments, and non markup portions of your code. Line and column numbers provide reference points to help you navigate code.

When you are ready to test your code, you are only a single click away from passing content to preinstalled Openwave Browser Simulators. Simultaneously, you can check that your code renders correctly and see the source. Using the HTTP Response view, you can also collapse and expand the current code structure.

 Device Simulation

The SDK includes a number of preinstalled Openwave Browser Simulators, each of which replicates exactly the browsing capabilities of the real device, providing the tools to test and verify your code without releasing it to a live environment. Device selection is made easy with skin previews and technical summaries. From the address bar you can load files from the local file system. If you have access to the Internet, you can also simulate server content.

 DebuggingDebugging wireless content is made easy with a number of dedicated debugging views that display information about the variables, history, and cookies associated with the current session. Information returned from the browser is reported to the Browser Output window so you can see at glance information about HTTP status codes, content type, and compiled file size.

PRACTICAL 6

KALOL INSTITUTE OF TECHNOLOGY- 40 -

Page 41: Mobile Computing(2)

Mobile Computing

AIM: - Design a calculator using WML Script.

Theory:-

WML Tags:-

Card: This tag helps the user to create a card which acts as a canvas on which the user works for the application creation.

P: This tag helps the user to write in the canvas of the card that the user is using for creating the application.

Br: This tag is used to end the line.

B: This tag enables the text to be bold.

Do: This tag helps the user to create the options in the available options tab of the simulator and creates a new link.

Input: This enables developers to create a place in applications for users to enter data.

Select: The select element enables you to create a list of options for user selections.

Option: The option element contains a few attributes that can enhance the options list.

Functions:-

Extern keyword: By making a function extern we make it accessible globally.

Lang.parsefloat(String) : Returns a string as a decimal integer.

getVar(String) : Retrieves the contents of a browser variable.

setVar(String1,String2) : Sets a browser variable.

Refresh( ) : Specifies a WML <refresh> task.

Program:

<?xml version="1.0"?> KALOL INSTITUTE OF TECHNOLOGY

- 41 -

Page 42: Mobile Computing(2)

Mobile Computing

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="calc" title="Calculator">

<p> <b>Number 1:</b> <input type="text" name="num1" format="*N"/> <b>Operation:</b> <select name="op" value="+"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <b>Number 2:</b> <input type="text" name="num2" format="*N"/> <br/> = $(result)

<do type="accept" label="Calculate"> <go href="calculator.wmls#doCalc()"/> </do>

</p> </card> </wml>

Calculator.wmlsextern function doCalc(){var a = Lang.parseFloat(WMLBrowser.getVar("num1"));var b = Lang.parseFloat(WMLBrowser.getVar("num2"));var op = WMLBrowser.getVar("op");var c = invalid;

if (op == "+") c = a + b;

else if (op == "*") c = a * b;

else if (op == "-") c = a - b;

else c = a / b;

WMLBrowser.setVar("result", String.toString(c));WMLBrowser.refresh();

}

Output:

KALOL INSTITUTE OF TECHNOLOGY- 42 -

Page 43: Mobile Computing(2)

Mobile Computing

PRACTICAL 7KALOL INSTITUTE OF TECHNOLOGY

- 43 -

Page 44: Mobile Computing(2)

Mobile Computing

AIM: - Design a mobile phone book using WML Script.

Theory:-

WML Tags:-

Card: This tag helps the user to create a card which acts as a canvas on which the user works for the application creation.

P: This tag helps the user to write in the canvas of the card that the user is using for creating the application.

Br: This tag is used to end the line.

B: This tag enables the text to be bold.

Do: This tag helps the user to create the options in the available options tab of the simulator and creates a new link.

Input: This enables developers to create a place in applications for users to enter data.

Go: This tag helps the user to pass on control to the valid link after the anchor tag has been invoked.

Functions:-

Extern keyword: By making a function extern we make it accessible globally.

getVar(String) : Retrieves the contents of a browser variable.

setVar(String1,String2) : Sets a browser variable.

Refresh( ) : Specifies a WML <refresh> task.

Program:

KALOL INSTITUTE OF TECHNOLOGY- 44 -

Page 45: Mobile Computing(2)

Mobile Computing

<?xml version=“1.0”?><!DOCTYPE wml PUBLIC “-//OPENWAVE.COM//DTD WML 1.3//EN” “http://www.openwave.com/dtd/wml13.dtd”>

<!-- WML file created by the Openwave SDK -->

<wml> <card id=“MainCard” title=“This is a first card”>

<p> <b> This is our phone - Book</b> </p><p>

<do type = “accept” label=“Add”> <go href=“#card1”/> </do>

</p> </card> <card id=“card1” title=“This is a second card”>

<p><input type=“text” name=“name”/><input type=“text” name=“phoneno” format=“*N”/><do type =“accept” label=“Save”><go href=“#card2”/></do>

</p> </card> <card id = “card2” title=“The Saved message”> <p> <b> The Number is saved</b> </p> <do type = “accept” label=“View”> <go href=“phs.wmls#n()”/> </do> $(a)<br/>$(b) </card></wml>

phs.wmls/* WMLScript file created by the Openwave SDK */

extern function n(){

var a=WMLBrowser.getVar(“name”); var b=WMLBrowser.getVar(“phoneno”); WMLBrowser.setVar(“a”,a);WMLBrowser.setVar(“b”,String.toString(b));WMLBrowser.refresh();

}

Output:

KALOL INSTITUTE OF TECHNOLOGY- 45 -

Page 46: Mobile Computing(2)

Mobile Computing

PRACTICAL: 8

KALOL INSTITUTE OF TECHNOLOGY- 46 -

Page 47: Mobile Computing(2)

Mobile Computing

AIM: - Write a J2ME application to demonstrate basic MIDLet Operation by printing “Hello World”.

Hello.java

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

private Display myDisplay = null;private Form resultScreen;private StringItem resultField;private Command exit;public void startApp(){

myDisplay = Display.getDisplay(this);exit = new Command("EXIT", Command.SCREEN, 1);resultScreen = new Form("Hello World");resultScreen.addCommand(exit);resultField = new StringItem(null,"RoNaK SHaH");resultField = new StringItem(null,"Wel Come to Our");resultField = new StringItem(null,"World…!!");resultScreen.setCommandListener(this);resultScreen.append(resultField);myDisplay.setCurrent(resultScreen);

}public void pauseApp(){}

public void destroyApp(boolean unconditional){}

public void commandAction(Command c, Displayable displayable){

if (c == exit){

destroyApp(false);notifyDestroyed();

}}

}

KALOL INSTITUTE OF TECHNOLOGY- 47 -

Page 48: Mobile Computing(2)

Mobile Computing

OUTPUT:-

PRACTICAL: 9

KALOL INSTITUTE OF TECHNOLOGY- 48 -

Page 49: Mobile Computing(2)

Mobile Computing

AIM: Write a J2ME application for online help. Online Help will instruct users on interacting with the application.

online.javaimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class online extends MIDlet implements CommandListener{

private Display display;private Command back;private Command exit;private Command help;private Form form;private TextBox helpMesg;public online(){

display = Display.getDisplay(this);back = new Command("Back", Command.BACK, 2);exit = new Command("Exit", Command.EXIT, 1);help = new Command("Help", Command.HELP, 3);form = new Form("Online Help Example");helpMesg = new TextBox("Online Help", "Press Back to return to the

previous screen or press Exit to close this program.", 81, 0);helpMesg.addCommand(back);form.addCommand(exit);form.addCommand(help);form.setCommandListener(this);helpMesg.setCommandListener(this);

}public void startApp(){

display.setCurrent(form);}public void pauseApp(){}public void destroyApp(boolean unconditional){}public void commandAction(Command c,Displayable displayable){

if (c == back){

display.setCurrent(form);}else if (c == exit)

KALOL INSTITUTE OF TECHNOLOGY- 49 -

Page 50: Mobile Computing(2)

Mobile Computing

{destroyApp(false);notifyDestroyed();

}else if (c == help){

display.setCurrent(helpMesg);}

}}

OUTPUT:-

KALOL INSTITUTE OF TECHNOLOGY- 50 -

Page 51: Mobile Computing(2)

Mobile Computing

PRACTICAL: 10

KALOL INSTITUTE OF TECHNOLOGY- 51 -

Page 52: Mobile Computing(2)

Mobile Computing

AIM: Write a J2ME application for drawing rectangle and rounded rectangle.

rr.javaimport javax.microedition.midlet.*;import javax.microedition.lcdui.*;public class rr extends MIDlet{

private Display display;private MyCanvas canvas;public rr (){

display = Display.getDisplay(this);canvas = new MyCanvas (this);

}protected void startApp(){

display.setCurrent( canvas );}protected void pauseApp(){}protected void destroyApp( boolean unconditional ){}public void exitMIDlet(){

destroyApp(true);notifyDestroyed();

}}

class MyCanvas extends Canvas implements CommandListener{

private Command exit;private rr rectangleExample;public MyCanvas (rr rectangleExample){

this.rectangleExample = rectangleExample;exit = new Command("Exit", Command.EXIT, 1);addCommand(exit);setCommandListener(this);

}protected void paint(Graphics graphics){

graphics.setColor(255,255,255);

KALOL INSTITUTE OF TECHNOLOGY- 52 -

Page 53: Mobile Computing(2)

Mobile Computing

graphics.fillRect(0, 0, getWidth(), getHeight());graphics.setColor(255,0,0);graphics.drawRect(2, 2, 20, 20);graphics.drawRoundRect(20, 20, 60, 60, 15, 45);

}public void commandAction(Command command, Displayable displayable){

if (command == exit)rectangleExample.exitMIDlet();

}}

OUTPUT:-

KALOL INSTITUTE OF TECHNOLOGY- 53 -

Page 54: Mobile Computing(2)

Mobile Computing

PRACTICAL: 11

AIM: Design a calculator using .NET Compact framework.

KALOL INSTITUTE OF TECHNOLOGY- 54 -

Page 55: Mobile Computing(2)

Mobile Computing

Public Class Form1 Dim temp1 As Integer Dim opr As String Dim ctr As Integer Dim sg As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "1" Else TextBox1.Text = TextBox1.Text & "1" End If End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "2" Else TextBox1.Text = TextBox1.Text & "2" End If End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "3" Else TextBox1.Text = TextBox1.Text & "3" End If End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "4" Else

KALOL INSTITUTE OF TECHNOLOGY- 55 -

Page 56: Mobile Computing(2)

Mobile Computing

TextBox1.Text = TextBox1.Text & "4" End If End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "5" Else TextBox1.Text = TextBox1.Text & "5" End If End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "6" Else TextBox1.Text = TextBox1.Text & "6" End If End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "7" Else TextBox1.Text = TextBox1.Text & "7" End If End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "8" Else TextBox1.Text = TextBox1.Text & "8" End If End Sub

KALOL INSTITUTE OF TECHNOLOGY- 56 -

Page 57: Mobile Computing(2)

Mobile Computing

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "9" Else TextBox1.Text = TextBox1.Text & "9" End If End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click If ctr = "2" Then TextBox1.Text = "" ctr = 3 TextBox1.Text = "0" Else TextBox1.Text = TextBox1.Text & "0" End If End Sub

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click TextBox1.Text = "" End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click temp1 = TextBox1.Text opr = "+" ctr = 2 End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click If opr = "+" Then TextBox1.Text = temp1 + Val(TextBox1.Text) End If If opr = "-" Then TextBox1.Text = temp1 - Val(TextBox1.Text) End If If opr = "*" Then TextBox1.Text = temp1 * Val(TextBox1.Text) End If If opr = "/" Then If TextBox1.Text = "0" Then TextBox1.Text = "ERror...!!!"

KALOL INSTITUTE OF TECHNOLOGY- 57 -

Page 58: Mobile Computing(2)

Mobile Computing

Else TextBox1.Text = temp1 / Val(TextBox1.Text) End If End If End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click temp1 = TextBox1.Text opr = "-" ctr = 2 End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click temp1 = TextBox1.Text opr = "*" ctr = 2 End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click temp1 = TextBox1.Text opr = "/" ctr = 2 End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click If TextBox1.Text.IndexOf(".") = "-1" Then If TextBox1.Text = "" Then TextBox1.Text = "0" End If TextBox1.Text = TextBox1.Text & "." End If End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click TextBox1.Text = Str(Val(1 / TextBox1.Text)) End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click TextBox1.Text = Str(Val((TextBox1.Text) * (TextBox1.Text))) End Sub

KALOL INSTITUTE OF TECHNOLOGY- 58 -

Page 59: Mobile Computing(2)

Mobile Computing

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click If TextBox1.Text = "" Then

Else TextBox1.Text = -(TextBox1.Text) End If End SubEnd Class

OUTPUT:-

KALOL INSTITUTE OF TECHNOLOGY- 59 -

Page 60: Mobile Computing(2)

Mobile Computing

KALOL INSTITUTE OF TECHNOLOGY

- 60 -

Page 61: Mobile Computing(2)

Mobile Computing

PRACTICAL: 12

AIM: Design a mobile phone book .NET Compact framework.

Main.csusing System;using System.Linq;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlServerCe;

namespace goyaniphbook12{ public partial class main : Form { string path = "Data Source =" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\userbook12.sdf"; public main()

KALOL INSTITUTE OF TECHNOLOGY- 61 -

Page 62: Mobile Computing(2)

Mobile Computing

{ InitializeComponent(); } public DataTable executeSelectQuery(String query) { SqlCeConnection connection = new SqlCeConnection(path); connection.Open(); SqlCeDataAdapter adapter = new SqlCeDataAdapter(query, connection); DataTable dt = new DataTable(); adapter.Fill(dt); return dt; } private void menuItem1_Click(object sender, EventArgs e) { Form1 obj = new Form1(); obj.Show(); }

private void main_Load(object sender, EventArgs e) { String query = "SELECT fname AS Name, mob AS Mobile FROM tblbook12"; dgGoyani.DataSource = executeSelectQuery(query); }

private void dgGoyani_DoubleClick(object sender, EventArgs e) {

}

private void dgGoyani_CurrentCellChanged(object sender, EventArgs e) {

} private void menuItem4_Click(object sender, EventArgs e) { frmedit obj = new frmedit(); obj.Show(); }

private void menuItem5_Click(object sender, EventArgs e) { frmdelete obj = new frmdelete(); obj.Show(); } }}

KALOL INSTITUTE OF TECHNOLOGY- 62 -

Page 63: Mobile Computing(2)

Mobile Computing

Form1.csusing System;using System.Linq;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Data.SqlServerCe;

namespace goyaniphbook12{ public partial class Form1 : Form { string path = "Data Source =" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\userbook12.sdf"; public Form1() {

InitializeComponent(); } public void executeInsertQuery(String query) { SqlCeConnection connection = new SqlCeConnection(path); connection.Open(); SqlCeCommand sqlcmd = new SqlCeCommand(query); sqlcmd.Connection = connection; SqlCeDataAdapter adapter = new SqlCeDataAdapter(sqlcmd); sqlcmd.ExecuteNonQuery(); connection.Close(); MessageBox.Show("successfully Inserted"); }

private void button1_Click(object sender, EventArgs e) { string query = "INSERT INTO tblbook12 values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')"; executeInsertQuery(query); }

private void Form1_Load(object sender, EventArgs e) {

KALOL INSTITUTE OF TECHNOLOGY- 63 -

Page 64: Mobile Computing(2)

Mobile Computing

}

private void menuItem1_Click(object sender, EventArgs e) { main obj = new main(); obj.Show(); } }}

frmedit.csusing System;using System.Linq;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlServerCe;

namespace goyaniphbook12{ public partial class frmedit : Form { string path = "Data Source =" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\userbook12.sdf"; public frmedit() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("enter the name"); } else { label6.Enabled=true; edittextBox1.Enabled = true; label5.Enabled = true; edittextBox2.Enabled = true;

KALOL INSTITUTE OF TECHNOLOGY- 64 -

Page 65: Mobile Computing(2)

Mobile Computing

label3.Enabled = true; edittextBox3.Enabled = true; label4.Enabled = true; edittextBox4.Enabled = true; editbutton1.Enabled = true; } } private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("enter the name"); } } public void executeUpdateQuery(String query) { SqlCeConnection connection = new SqlCeConnection(path); connection.Open(); SqlCeCommand sqlcmd = new SqlCeCommand(query); sqlcmd.Connection = connection; SqlCeDataAdapter adapter = new SqlCeDataAdapter(sqlcmd); sqlcmd.ExecuteNonQuery(); connection.Close(); MessageBox.Show("successfully Updated"); } private void editbutton1_Click_1(object sender, EventArgs e) { string query = "UPDATE tblbook12 SET fname='" +edittextBox1.Text+ "',lname='" + edittextBox2.Text + "',mob='" + edittextBox3.Text+ "',tel='" + edittextBox4.Text+ "' WHERE fname='" + textBox1.Text+ "'"; executeUpdateQuery(query); }

private void menuItem1_Click(object sender, EventArgs e) { main obj = new main(); obj.Show(); }

private void frmedit_Load(object sender, EventArgs e) { } }}

frmdelete.cs

KALOL INSTITUTE OF TECHNOLOGY- 65 -

Page 66: Mobile Computing(2)

Mobile Computing

using System;using System.Linq;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlServerCe;

namespace goyaniphbook12{ public partial class frmdelete : Form { string path = "Data Source =" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\userbook12.sdf"; public frmdelete() { InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) {

}

private void textBox1_TextChanged(object sender, EventArgs e) {

} public void executeDeleteQuery(String query) { SqlCeConnection connection = new SqlCeConnection(path); SqlCeCommand sqlcmd = new SqlCeCommand(query); connection.Open(); sqlcmd.Connection = connection; sqlcmd.ExecuteNonQuery(); connection.Close(); MessageBox.Show("successfully Deleted"); } private void deletebutton1_Click(object sender, EventArgs e) { string query = "DELETE FROM tblbook12 WHERE fname='" + textBox1.Text + "'"; executeDeleteQuery(query); }

KALOL INSTITUTE OF TECHNOLOGY- 66 -

Page 67: Mobile Computing(2)

Mobile Computing

private void menuItem1_Click(object sender, EventArgs e) { main obj = new main(); obj.Show(); }

private void textBox1_TextChanged_1(object sender, EventArgs e) {

} }}

OUTPUT:-

KALOL INSTITUTE OF TECHNOLOGY- 67 -

Page 68: Mobile Computing(2)

Mobile Computing

KALOL INSTITUTE OF TECHNOLOGY- 68 -

Page 69: Mobile Computing(2)

Mobile Computing

KALOL INSTITUTE OF TECHNOLOGY- 69 -