Monday, November 4, 2013

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);
}
}
}

Sunday, November 3, 2013

phone application

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.Form;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.*;

public class Myph extends MIDlet implements CommandListener{
   
    private Form fm;
    private List lst;
    private TextBox tb;
    private Command exit,send,back,call,contacts,message;
    private Display d;
    public Myph()
    {
        d=Display.getDisplay(this);
        fm=new Form("my phone");
        tb=new TextBox("message Box",null,500,0);//500 characters can be text
        lst=new List("contacts",List.IMPLICIT);
        lst.append("mom 98491",null);
        lst.append("dad 9900...",null);
        lst.append("bro 888..",null);
        lst.append("rajendra 9849186838",null);
        exit=new Command("Exit", Command.EXIT,1);
        back=new Command("Back", Command.BACK,1);
        send=new Command("Send", Command.OK,1);
        call=new Command("Call", Command.OK,1);
        message=new Command("Mesaage Box", Command.OK,2);
        contacts=new Command("Contacts List", Command.OK,1);
       
        fm.addCommand(exit);
        fm.addCommand(message);
        fm.addCommand(contacts);
        tb.addCommand(back);
        tb.addCommand(send);
        lst.addCommand(call);
      //  tb.addCommand(call);//call option is not visible
        fm.setCommandListener(this);
        tb.setCommandListener(this);
        lst.setCommandListener(this);
         }
   
   
    public void startApp() {
        d.setCurrent(fm);
       
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable dd) {
        if(c==exit)
        {
            destroyApp(false);
            notifyDestroyed();
           
        }
        else if(c==contacts)
        {
            Alert al=new Alert("welcome");
            al.setString("keep in touch with your dear ones");
            d.setCurrent(al,lst);
             
        }
        else if(c==message)
        {
            Alert al=new Alert("welcome");
            al.setString("Happy messaging");
            al.setType(AlertType.INFO);
           
            d.setCurrent(al,tb);
        }
        else if(c==back)
        {
            d.setCurrent(fm);
        }
        else if(c==send)
        {
            Alert al=new Alert("Messaging Service");
            al.setString("msg is sent successfully");
            al.setType(AlertType.INFO);
            d.setCurrent(al,fm);
        }
        else if(c==call)
        {
            Alert al=new Alert("calling..");
            al.setString("No networking coverage");
            al.setType(AlertType.INFO);
          //  al.setType(AlertType.ERROR);
           // d.setCurrent(al,tb);//it will go msg box
            d.setCurrent(al,fm);
           
        }
    }
}

ImageTutorial

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ImageTutorial extends MIDlet
{
 Display d;
 Form f;
 Image i;
 public ImageTutorial()
 {
 
  d=Display.getDisplay(this);
  //save any image in C:\Documents and Settings\admin\My Documents\NetBeansProjects\unit3\src
  f=new Form("image application");
   try
   {
    i=Image.createImage("/suhas8.jpg");
  //  i=Image.createImage("C:\\Documents and Settings\\admin\\My Documents\\NetBeansProjects\\unit3\\src\\suhas8.jpg");
    f.append(i);
    }
  catch(Exception ex)
  {
  }
 }  
    public void startApp() {
        d.setCurrent(f);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}