Monday, November 4, 2013

How to Install and execute J2ME software

1.

2.
Go to oracle.com
And type in the search box: j2me windows toolkit 2.2 windows.exe
3. you will find the following page

4. come to down of the page and choose   J2ME Wireless Toolkit 2.2

5. click that link
6. run that software
Setting the class path
1.       Go to my computer
2.       C:\Program Files\Java\jdk1.6.0_20\bin;.;
3.      
Variable: classpath
C:\WTK22\bin;.;C:\WTK22\lib;.;C:\Java_ME_platform_SDK_8.0_EA\bin;C:\Java_ME_platform_SDK_8.0_EA\lib;
4.       Go to start->programs->j2me wireless toolkit->toolbar
5.       Go to new project
6.       Type the project name any
7.       Type the our class name
8.       Click on build
9.       Click on run

Installation Checklist
PATH=c:\jdk1.3\bin; c:\j2me\j2me_cldc\bin;c:\j2me\midp-fcs\bin;

1.        

DateField class

package unit3;

import java.util.Date;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class DateEx extends MIDlet implements CommandListener
{
    private Display d;
    private Form f;
    private Date dat;
    private Command exit;
    private DateField df;
    public DateEx()
    {
        d=Display.getDisplay(this);
        f=new Form("To day's date");
        dat=new Date(System.currentTimeMillis());
        df=new DateField("",DateField.DATE_TIME);
        df.setDate(dat);
        exit=new Command("Exit",Command.EXIT,1);
        f.append(df);
        f.addCommand(exit);
        f.setCommandListener(this);
   
    }

    public void startApp() {
        d.setCurrent(f);
       
    }
       
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command c,Displayable dd)
    {
        if(c==exit)
        {
            destroyApp(false);
            notifyDestroyed();
        }
    }
    public void pauseApp() {
    }
}

Radiobutton

import javax.microedition.midlet.MIDlet;
//import javax.microedition.lcdui.*;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Displayable;
public class RadioButtons extends MIDlet implements ItemStateListener,CommandListener
{
 private Display d;
 private Form f;
 private Command exit;
 private Item it;
 private ChoiceGroup rb;
 private int n;
 private int rn;
 public RadioButtons()
 {
  //   d=new Display("");
  //   d.getDisplay(this);
  d=Display.getDisplay(this);
  f=new Form("");
  rb=new ChoiceGroup("select color", Choice.EXCLUSIVE);
  rb.append("Red", null);
  rb.append("white",null);
  rb.append("Blue",null);
  rb.append("Green",null);
  //n=rb.append("all",null);//append method returns index no of the optionr
  //rb.setSelectedIndex(rn,true);//optional
  rb.append("all",null);
  exit=new Command("Exit",Command.EXIT,1);
  //f=new Form("");
//  n=f.append(rb);//omits output is not displayed
  f.append(rb);
  f.addCommand(exit);
  f.setCommandListener(this);
  f.setItemStateListener(this);//omits,selected item is not displayed
   //d=Display.getDisplay(this);//we can write here also
 }
 public void startApp()
 {
   d.setCurrent(f);
 }
 public void pauseApp()
 {
 }
 public void destroyApp(boolean un)
 {
 }
 public void commandAction(Command c, Displayable dis)
 {
  if(c==exit)
  {
   destroyApp(true);
   notifyDestroyed();
  }
 }
public void itemStateChanged(Item i)
{
 if(i==rb)
 {
  StringItem si=new StringItem("selected",rb.getString(rb.getSelectedIndex()));
  f.append(si);
 }
}
}

SoundAlert

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class SoundAlertExample extends MIDlet implements ItemStateListener, CommandListener{
private Display display;  
private Form form;    
private Command exit;    
private ChoiceGroup choice;

public void startApp(){
display = Display.getDisplay(this);
choice = new ChoiceGroup("List of Sound", Choice.EXCLUSIVE);
choice.append("Message Tone", null);  
choice.append("Confirmation Tone", null);  
choice.append("Warning Tone", null);          
choice.append("Alarm Tone", null);      
choice.append("Error Tone", null);  
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("");
form.append(choice);
form.addCommand(exit);
form.setCommandListener(this);  
form.setItemStateListener(this);
display.setCurrent(form);
}

public void pauseApp(){ }

public void destroyApp(boolean unconditional){
notifyDestroyed();
}

public void commandAction(Command c, Displayable s){
String label = c.getLabel();
if(label.equals("Exit")){
destroyApp(false);
}
}

public void itemStateChanged(Item item){
switch (choice.getSelectedIndex()){
case 0:
AlertType.INFO.playSound(display);
break;

case 1:
AlertType.CONFIRMATION.playSound(display);
break;

case 2:
AlertType.WARNING.playSound(display);
break;

case 3:
AlertType.ALARM.playSound(display);
break;

case 4:
AlertType.ERROR.playSound(display);
break;
}
}
}

GameAction

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class GameActionExample extends MIDlet
{
 private Display d;
 private MyCanvas2 c;
 public GameActionExample()
 {
  d=Display.getDisplay(this);
  c=new MyCanvas2(this);
 }
 protected void startApp()
 {
  d.setCurrent(c);
 }
 protected void pauseApp()
 {
 }
 protected void destroyApp(boolean b)
 {
 }

class MyCanvas2 extends Canvas implements CommandListener
{
 private Command exit;
 private String m,dir;
 private GameActionExample gae;
 private int x,y;
 public MyCanvas2 (GameActionExample gae)
 {
  x=5;
  y=5;
  dir="use Game keys";
  this.gae=gae;
  exit=new Command("Exit",Command.EXIT,1);
  addCommand(exit);
  setCommandListener(this);
 }
 protected void paint(Graphics g)
 {
  g.setColor(255,255,255);
  g.fillRect(0,0,getWidth(),getHeight());
  g.setColor(255,0,0);
  g.drawString(m,x,y,Graphics.TOP|Graphics.LEFT);
 }
 public void commandAction(Command c, Displayable dd)
 {
  if(c==exit)
  {
   destroyApp(true);
  notifyDestroyed();
  }
}
protected void keyPressed(int key)
{
 switch(getGameAction(key))
 {
  case Canvas.UP:
    m="up";
    y--;
    break;
  case Canvas.DOWN:
   m="down";
   y++;
   break;
  case Canvas.LEFT:
   m="left";
   break;
  case Canvas.RIGHT:
   m="right";
   x++;
   break;
  case Canvas.FIRE:
   m="FIRE";
   break;
  }//switch
  repaint();
 }
}  
 

Ticker class


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

{
 private Display d;
 private List list;
 private final String tech;
 private final String movies;
 private Ticker t;
 private Command exit;
 private Command submit;
 public TickerList()
 {
  d=Display.getDisplay(this);
  tech=new String("c  c++ java sap android");
  movies=new String("jalsa athadu chennai express");
  exit=new Command("Exit", Command.SCREEN,1);
  submit=new Command("Submit", Command.SCREEN,1);
  t=new Ticker(tech);
  list=new List("News", Choice.EXCLUSIVE);
  list.append("Technology",null);
  list.append("Movies",null);
  list.addCommand(exit);
  list.addCommand(submit);
  list.setCommandListener(this);
  list.setTicker(t);
}
public void startApp()
{
 d.setCurrent(list);
}
public void pauseApp()
{
}
public void destroyApp(boolean b)
{
}
public void commandAction(Command c,Displayable dd)
{
 if(c==exit)
 {
   destroyApp(true);
   notifyDestroyed();
 }
 else if(c==submit)
 {
  if(list.getSelectedIndex()==0)
  {
   t.setString(tech);
  }
  else
  {
   t.setString(movies);
  }
}
}
}

List Image

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ListImage extends MIDlet implements CommandListener{
private Display display;
private List list;
private Command exit, next;
private Image car, plane, hotel, mob;
String[] s = {"Aero plane", "Car", "Mobile"};

public ListImage(){
try{
plane = Image.createImage("/suhas8.jpg");
car = Image.createImage("/suhas8.jpg");

mob = Image.createImage("/suhas8.jpg");

}catch(Exception e){
//System.err.println(e.getMessage());
}
}

public void startApp() {
display = Display.getDisplay(this);
Image[] i = {airplane, car, mobile};
list = new List("List + Image", List.IMPLICIT, s, i);
next = new Command("Select", Command.SCREEN, 0);
exit = new Command("Exit", Command.EXIT, 0);
list.addCommand(next);
list.addCommand(exit);
list.setCommandListener(this);
display.setCurrent(list);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional){
notifyDestroyed();
}

public void commandAction(Command c, Displayable s){
int index = list.getSelectedIndex();
if (c == next || c == List.SELECT_COMMAND) {

                   
                    Alert alert=new Alert("selected","u r selected",list.getImage(index),null);
                     
                       
display.setCurrent(alert, list);
} else if(c == exit){
destroyApp(true);
}
}
}