Professional Documents
Culture Documents
package hello;
importjava.io.IOException;
importjavax.microedition.lcdui.*;
importjavax.microedition.midlet.*;
public class Midlet extends MIDlet implements CommandListener
{
private Display d;
private Form f;
private Command exit;
private Image img;
privateImageItemimt;
private Alert a;
publicMidlet()
{
d=Display.getDisplay(this);
exit=new Command("Exit",Command.EXIT,1);
f=new Form("Images");
f.addCommand(exit);
f.setCommandListener(this);
try
{
img=Image.createImage("/sachin.png");
imt=new ImageItem(null,img,ImageItem.LAYOUT_CENTER|ImageItem.LAYOUT_NEWLINE_BEFORE|
ImageItem.LAYOUT_NEWLINE_BEFORE,"Sachin");
f.append(imt);
}
catch(java.io.IOException error)
{
a=new Alert("Error","Cant load the images",null,null);
a.setTimeout(Alert.FOREVER);
a.setType(AlertType.ERROR);
d.setCurrent(a);
}
}
public void startApp() {
d.setCurrent(f);
}
package hello;
importjavax.microedition.midlet.MIDlet;
importjavax.microedition.lcdui.*;
publicMidlet() {
form = new Form("Sign in");
userName = new TextField("LoginID:", "", 30, TextField.ANY);
password = new TextField("Password:", "", 30, TextField.PASSWORD);
cancel = new Command("Cancel", Command.CANCEL, 2);
login = new Command("Login", Command.OK, 2);
try{
img1= Image.createImage("/sachin.png");
img2=Image.createImage("/fail.png");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
publicMidlet(){
try{
airplane = Image.createImage("/airoplane.png");
car = Image.createImage("/car.png");
hotel = Image.createImage("/hotel.png");
mobile = Image.createImage("/mobile.png");
cartoon = Image.createImage("/sachin.png");
}catch(Exception e){
System.err.println(e.getMessage());
}
}
package mobileapplication1;
importjava.util.*;
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
importjava.util.Timer;
importjava.util.TimerTask;
importjavax.microedition.media.*;
public class Midlet extends MIDlet implements ItemStateListener, CommandListener
{
private Display display; // Reference to display object
private Form fmMain; // The main form
private Command cmSnooze; // Start the timer
private Command cmReset; // Reset to current date/time
private Command cmExit; // Exit the MIDlet
privateDateFielddfSnoozeTime; // How long to snooze
privateintdateIndex; // Index of the DateField on the Form
private Date currentTime; // Current time...changes when pressing reset
private Timer tmSnooze; // The timer - keeps track of system time
privateSnoozeTimerttSnooze; // Called by the timer
privatebooleandateOK = false;
private Image img;// Was the user input valid?
publicMidlet()
{
display = Display.getDisplay(this);
// The main form
fmMain = new Form("When to sound the alarm:");
// Save today's date
currentTime = new Date();
{
img=Image.createImage("a.png");
}
catch(Exception e)
{
}
}
public void startApp ()
{
display.setCurrent(fmMain);
}
public void pauseApp()
{}
5)ChoiceGroup Class
package mobileapplication11;
import java.io.*;
importjavax.microedition.midlet.*;
importjavax.microedition.media.*;
importjavax.microedition.lcdui.*;
case 1:
try{
player2.start();
package mobileapplication13;
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
t.addCommand(quit);
t.setCommandListener(this);
}
}
}
7) Simple HelloWorldMidlet
package mobileapplication14;
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
8)Ticker Class
package tic;
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
publicMidlet()
{
disp=Display.getDisplay(this);
quit=new Command("QUIT",Command.SCREEN,0);
submit=new Command("SUBMIT",Command.SCREEN,1);
lis=new List("Stock",Choice.EXCLUSIVE);
s1=new String("21.0 19.0");
s2=new String("76.0,90.0");
tic=new Ticker(s1);
lis.append("Stock1",null);
lis.append("Stock2",null);
lis.addCommand(quit);
lis.addCommand(submit);
lis.setCommandListener(this);
lis.setTicker(tic);
importjavax.microedition.rms.*;
importjavax.microedition.midlet.*;
importjavax.microedition.lcdui.*;
import javax.microedition.io.*;
publicMidlet()
{
openRecStore(); // Create the record store
try
{
rs.addRecord(rec, 0, rec.length);
}
catch (Exception e)
{
db(e.toString());
}
}
/*--------------------------------------------------
* Simple message to console for debug/errors
*-------------------------------------------------*/
private void db(String str)
{
System.err.println("Msg: " + str);
}