Professional Documents
Culture Documents
Embedded Lab File
Embedded Lab File
Lab File
Made By:
Atishay Jain
10783017
Harsh Dhaka
10603039
Mayank Gupta
10603055
Contents
Below are the instructions to install and Setup J2ME in Windows XP SP2:
i) Install Java SDK. Double Click on Sun Java SDK installer package.
ii) Click Accept to accept the license agreement.
iii) Click Next after selecting packages to install.
iv) Click Next for directory selection.
v) Click Finish to accept the Java SDK and JRE installation.
vi) Double click on Sun Java Mobile SDK Toolkit setup.
vii) Click Accept to accept the license agreement. Click Next.
viii) Accept the location of JDK selected, if unavailable find JDK. Click next to select the
directory
ix) Click next after update selection.
x) Unblock the firewall.
xi) Click Finish. J2ME is installed.
package textbox;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
/**
* The textbox demo displays a list of all the text box types and allows the
* user to select a specific type of text box to try.
*
* @version 2.0
*/
public class TextBoxDemo extends MIDlet implements CommandListener {
private static final Command CMD_EXIT = new Command ("Exit", Command.EXIT, 1);
private static final Command CMD_BACK = new Command ("Back", Command.BACK, 1);
private static final Command CMD_SHOW = new Command ("Show", Command.SCREEN,
1);
/**
* The labels for the supported textboxs.
*/
static final String[] textBoxLabels =
{"Any Character", "E-Mail", "Number", "Decimal", "Phone", "Url"};
/**
* The supported textbox types.
*/
static final int[] textBoxTypes =
{
TextField.ANY, TextField.EMAILADDR, TextField.NUMERIC, TextField.DECIMAL,
TextField.PHONENUMBER, TextField.URL
};
private Display display;
private ChoiceGroup types;
private ChoiceGroup options;
private Form mainForm;
private boolean firstTime;
public TextBoxDemo () {
display = Display.getDisplay (this);
firstTime = true;
}
// advanced options
String[] optionStrings = {"As Password", "Show Ticker"};
options = new ChoiceGroup ("Options", Choice.MULTIPLE, optionStrings, null);
mainForm.append (options);
mainForm.addCommand (CMD_SHOW);
mainForm.addCommand (CMD_EXIT);
mainForm.setCommandListener (this);
firstTime = false;
}
display.setCurrent (mainForm);
}
if (flags[0]) {
choiceType |= TextField.PASSWORD;
}
if (flags[1]) {
textBox.setTicker (new Ticker ("TextBox: " + title));
}
textBox.addCommand (CMD_BACK);
textBox.setCommandListener (this);
display.setCurrent (textBox);
}
else if (c == CMD_BACK) {
display.setCurrent (mainForm);
}
}
}
Important Commands:
Functions Used:
Printing a simple Line “Hello World” in J2ME Environment
using CLDC Toolkit.
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public HelloMIDlet() {
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.EXIT, 0);
}
t.addCommand(exitCommand);
t.setCommandListener(this);
display.setCurrent(t);
}
}
Write a program to create a set of Radio Buttons and
Select a Desired One.
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public ListRadioButtons() {
display = Display.getDisplay(this);
list.append("Male", null);
list.append("Female", null);
list.addCommand(exit);
list.addCommand(submit);
list.setCommandListener(this);
}
public CheckBoxes() {
display = Display.getDisplay(this);
movies.append("A", null);
movies.append("B", null);
movies.append("C", null);
movies.append("D", null);
movieIndex = form.append(movies);
form.addCommand(exit);
form.addCommand(process);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
// Exit command
private static final Command EXIT_COMMAND =
new Command("Exit", Command.EXIT, 0);
// OK command
private static final Command OK_COMMAND =
new Command("OK", Command.OK, 0);
// Command implementations.
public void commandAction(Command c, Displayable d) {
if (c == EXIT_COMMAND) {
destroyApp(true);
notifyDestroyed();
} else if (c == OK_COMMAND) {
System.out.println("OK pressed");
} else if (c == CLEAR_COMMAND) {
textBox.setString(null);
} else if (c == REVERSE_COMMAND) {
String str = textBox.getString();
if (str != null) {
StringBuffer sb = new StringBuffer(str);
textBox.setString(sb.reverse().toString());
}
}
}
}
// The TextBox
protected TextBox textBox;
started = true;
}
}
Filled Rectangle
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public FilledRectangleExample() {
display = Display.getDisplay(this);
canvas = new MyCanvas(this);
}
Rectangle Boundary
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public RectangleExample() {
display = Display.getDisplay(this);
canvas = new MyCanvas(this);
}
protected void startApp() {
display.setCurrent(canvas);
}
Outline only
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public ArcExampleMIDlet() {
display = Display.getDisplay(this);
canvas = new MyCanvas(this);
}
Filled Arc
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public ArcFilledExample() {
display = Display.getDisplay(this);
canvas = new MyCanvas(this);
}