0% found this document useful (0 votes)
63 views21 pages

Experiment-1 (Hello World) : Code

The document contains source code for several MIDP experiments including: 1. A "Hello World" program that displays text in a text box 2. A form navigation program that allows the user to enter text and navigate between two forms 3. An immutable image program that displays an image on a form 4. A mutable image program that draws an arc on a mutable image 5. A ticker program that displays scrolling text in a text box 6. A gauge program that displays interactive and non-interactive gauges 7. A date and time program that displays the current date and time in a date field.

Uploaded by

Rushi Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views21 pages

Experiment-1 (Hello World) : Code

The document contains source code for several MIDP experiments including: 1. A "Hello World" program that displays text in a text box 2. A form navigation program that allows the user to enter text and navigate between two forms 3. An immutable image program that displays an image on a form 4. A mutable image program that draws an arc on a mutable image 5. A ticker program that displays scrolling text in a text box 6. A gauge program that displays interactive and non-interactive gauges 7. A date and time program that displays the current date and time in a date field.

Uploaded by

Rushi Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

DAVLEEN KAUR MATTA

BE-4/B

ROLL NO-33

EXPERIMENT-1(HELLO WORLD)
Code-

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloWorld extends

MIDlet implements

CommandListener

private Display display ;

private TextBox textBox ;


private Command quitCommand;
public void startApp()

display =

Display.getDisplay(this); quitCommand
= new

Command("Quit",

Command.SCREEN, 1);

textBox = new

TextBox("Hello World", "My first


MIDlet", 40, 0);

textBox

.addCommand(quitCommand);

textBox

.setCommandListener(this);

display .setCurrent(textBox );

public void pauseApp()

{
}

public void destroyApp(boolean


unconditional)

public void

commandAction(Command choice,

Displayable displayable)

if (choice == quitCommand)

destroyApp(false);
notifyDestroyed();

}
Output-
DAVLEEN KAUR MATTA
BE-4/B
ROLL NO-33

EXPERIMENT-FORM NAVIGATION

CODE:

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

public class FormNavigation extends MIDlet implements CommandListener

private Form f1,f2;

private TextField tf1,tf2;

private Display display;

private Command cmd = new Command("Navigate",Command.OK,0);

private Command exit_cmd = new Command("Exit",Command.EXIT,0);

public void startApp()

tf1 = new TextField("Enter your name : ","",10,TextField.ANY);

f1 = new Form("My Form 1");

f1.append(tf1);

f1.addCommand(cmd);

f1.setCommandListener(this);

display = Display.getDisplay(this);

display.setCurrent(f1);

public void pauseApp(){}

public void destroyApp(boolean unconditional){}

public void commandAction(Command c,Displayable d)

{
if(c==cmd)

tf2 = new TextField("Your name : ",tf1.getString(),10,TextField.ANY);

f2 = new Form("My Form 2");

f2.append(tf2);

display.setCurrent(f2);

if(c==exit_cmd){

destroyApp(false);

notifyDestroyed();

}
OUTPUT:
Shivani Rakesh Mehta
EXPERIMENT-
EXPERIMENT-IMMUTABLE IMAGE RollBE-3/A
No.:12

Experiment 2
Immutable Image
Source Code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ImmutableImage extends MIDlet implements CommandListener


{
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Display display;
private Form form;
private Image image;
private ImageItem imageItem;
public void startApp()
{
display = Display.getDisplay(this);
form = new Form("Immutable Image");
try {
image = Image.createImage("/image.png");
form.append(image);
display.setCurrent(form);
} catch(java.io.IOException error){}
form.addCommand(exitCommand);
form.setCommandListener(this);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s)
{
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
Shivani Rakesh Mehta
BE-3/A
Roll No.: 12

Output:
Harnish Savadia
BE4/D
Roll No:66
EXPERIMENT-MUTABLE IMAGE
MADT Practical
Mutable Image Program:
Source code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class MutableImageProgram extends MIDlet
{
private Image image;
private Display display;
private Form form;
private ImageItem imageItem;
public void startApp()
{
form = new Form("Image");
display = Display.getDisplay(this);
image = Image.createImage(70, 70);
Graphics graphics = image.getGraphics();
graphics.setColor(130, 0, 0);
graphics.fillArc(10, 10, 60, 50, 360, 180);
imageItem = new ImageItem("Image: ARC",
image,ImageItem.LAYOUT_CENTER,"");
form.append(imageItem);
display.setCurrent(form);
}
public void pauseApp()
{}
public void destroyApp(boolean u)
{
destroyApp(false);
notifyDestroyed();
}
}
Harnish Savadia
BE4/D
Roll No:66
DAVLEEN KAUR MATTA

BE-4/B

ROLL NO-33

EXPERIMENT-TICKER
Source Code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class TickerProgram extends MIDlet implements CommandListener


{
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Display display; public void startApp() {
display = Display.getDisplay(this);
TextBox t = new TextBox("Hello", "Welcome to MIDP Programming", 256, 0);
Ticker aTicker = new Ticker("ticker");
t.setTicker(aTicker);
t.addCommand(exitCommand);
t.setCommandListener(this);
display.setCurrent(t);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s)
{
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
Output:
DAVLEEN KAUR MATTA
Shivani Rakesh Mehta
BE-4/B
BE-3/A
ROLL NO-33
Roll No.:12

EXPERIMENT-GAUGE
Experiment 2
Gauge
Source Code:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class GaugeProgram extends MIDlet implements CommandListener


{
private Form form;
private Display display;
private Command back;
private Gauge gauge1, gauge2;
public void startApp()
{
Form form = new Form("GaugeExample");
back = new Command("Exit", Command.EXIT, 0);
display = Display.getDisplay(this);
gauge1 = new Gauge("Interactive", true, 100, 40);
gauge2 = new Gauge("Non-interactive", false, 100, 40);
form.append(gauge1);
form.append(gauge2);
form.addCommand(back);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
public void commandAction(Command c, Displayable s)
{
String label = c.getLabel();
if (label.equals("Exit"))
{
destroyApp(false);
}
}
}
Shivani Rakesh Mehta
BE-3/A
Roll No.:12

Output:
DAVLEEN KAUR MATTA

BE-4/B

ROLL NO-33

EXPERIMENT-
DATE&TIME

CODE-

import java.util.*; import


javax.microedition.lcdui.*; import
javax.microedition.midlet.MIDlet;
public class DateTime extends
MIDlet

{ private Display
display; protected
void startApp()

display = Display.getDisplay(this);

Form form = new Form("Demo");

DateField timeOnly = new

DateField("Time",DateField.DATE_TIME,TimeZone.getTimeZon
e("IST"));
form.append(timeOnly); display.setCurrent(form);

protected void pauseApp(){} protected void


destroyApp(boolean unconditional){}

OUTPUT:

You might also like