0% found this document useful (0 votes)
32 views6 pages

J2me Lab

This document outlines steps to develop J2ME programs and includes two sample programs. It provides instructions on starting the Java Wireless Toolkit, creating a new project, building and running the program. The first sample program prints "Hello World". The second program demonstrates changing font size and style by drawing text with different fonts to the canvas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

J2me Lab

This document outlines steps to develop J2ME programs and includes two sample programs. It provides instructions on starting the Java Wireless Toolkit, creating a new project, building and running the program. The first sample program prints "Hello World". The second program demonstrates changing font size and style by drawing text with different fonts to the canvas.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

J2ME Lab

Steps to develop J2ME programs


Step-1:-Start ->AllPrograms->Sun Java Tool Kit->Wireless Tool Kit

Step-2:-Click New Project Enter project Name as FirstMidlet -> Enter


ClassName as HelloMidlet->click on Create Project

Step-3:- A setting window will open up. Accept the defaults by clicking ok in
that window.

Chebrolu Engineering College (HU)


Page 1

J2ME Lab

Step-4 Actual program


Step-5:-Place HelloMidlet.java in C:\Documents and
settings\ADMIN\j2mewtk\2.5.2\apps\FirstMidlet\src\
Step-6: In the ktoolbar main window click on the Build button. When the
build compiles successfully then click on the Run button.

Chebrolu Engineering College (HU)


Page 2

J2ME Lab
Experiment: 1
Aim: A J2ME program to print Hello World
package mobileapplication1;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends MIDlet implements CommandListener {
public HelloWorld() {
}
private void initialize() {
}
public void startMIDlet() {
switchDisplayable(null, getForm());
}
public void resumeMIDlet() {
}
public void startApp() {
Form f=new Form("First Program");
f.append("Hello World");
Display.getDisplay(this).setCurrent(f);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
OUTPUT

Chebrolu Engineering College (HU)


Page 3

J2ME Lab

Experiment: 2
Aim: A J2ME program to show how to change the font size and color
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class FontCanvasMIDlet extends MIDlet {
public FontCanvasMIDlet() { // constructor
}
public void startApp() {
Canvas canvas = new FontCanvas();
Display display = Display.getDisplay(this);
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
class FontCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);

Chebrolu Engineering College (HU)


Page 4

J2ME Lab
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_
LARGE));
g.drawString("System Font", 0, 0, g.LEFT | g.TOP);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_
MEDIUM));
g.drawString("Medium Size", 0, 15, g.LEFT | g.TOP);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_
MEDIUM));
g.drawString("Bold Style", 0, 30, g.LEFT | g.TOP);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_
MEDIUM));
g.drawString("Italic Style", 0, 45, g.LEFT | g.TOP);
g.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_UNDERLINED, Fon
t.SIZE_MEDIUM));
g.drawString("Underlined Style", 0, 60, g.LEFT | g.TOP);
}
}

OUTPUT

Chebrolu Engineering College (HU)


Page 5

J2ME Lab

Chebrolu Engineering College (HU)


Page 6

You might also like