0% found this document useful (0 votes)
14 views

Java Phone Number

The document discusses creating a slideshow application in Java ME. It shows how to use threads to automatically transition between different forms displaying text or images at set intervals, and includes an exit command.

Uploaded by

Shruti David
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Java Phone Number

The document discusses creating a slideshow application in Java ME. It shows how to use threads to automatically transition between different forms displaying text or images at set intervals, and includes an exit command.

Uploaded by

Shruti David
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

phone number

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TextFielda extends MIDlet implements
CommandListener,ItemStateListener{
private Display display;
private Form form,nform;
private Command exit,next;
private TextField textField;

public TextFielda(){
display=Display.getDisplay(this);

form=new Form("phno check");


next=new Command("next",Command.SCREEN,0);
textField=new TextField("enter ur ph
no","123",12,TextField.PHONENUMBER);
form.append(textField);
form.addCommand(next);
form.setCommandListener(this);
form.setItemStateListener(this);
}
public void startApp(){

display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command command,Displayable displayable){
if(command==next){
display.setCurrent(nform);
}
if(command==exit){

notifyDestroyed();
}
}
public void itemStateChanged(Item item){
if(item==textField){
nform=new Form("result");
exit=new Command("exit",Command.EXIT,0);
if(textField.getString().startsWith("040")||
textField.getString().startsWith("041")||textField.getString().startsWith("050")||
textField.getString().startsWith("0400")||textField.getString().startsWith("044")){
if(textField.size()>=9){
nform.append("valid phone number");
}
}
else{
nform.append("invalid phone number");
}
nform.addCommand(exit);
nform.setCommandListener(this);
}

slideshow

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

public class SlideShow extends MIDlet implements CommandListener


{

private Display display;


private Form f1,f2,f3;
private Command exit;

public SlideShow()

{
display=Display.getDisplay(this);
exit=new Command("EXIT",Command.EXIT,1);

f1=new Form("first form");


f1.append("first slide");

f2=new Form("second form");


f2.append("second slide");

f3=new Form("third form");


f3.append("third slide");

f1.addCommand(exit);
f2.addCommand(exit);
f3.addCommand(exit);

f1.setCommandListener(this);
f2.setCommandListener(this);
f3.setCommandListener(this);
}
public void startApp()
{
Thread runner=new Thread(new ThreadRunner(display,f1,f2,f3));
runner.start();
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{

}
public void commandAction(Command c,Displayable display){

if(c==exit)
{
destroyApp(true);
notifyDestroyed();
}
}
class ThreadRunner implements Runnable{
Display display;
int c=0;
Form f1,f2,f3;
public ThreadRunner(Display display,Form f1,Form f2,Form f3){
this.display=display;
this.f1=f1;
this.f2=f2;
this.f3=f3;
}
public void run(){
while(true){
c++;
if(c==1)
display.setCurrent(f1);
else if(c==2)
display.setCurrent(f2);
else if(c==3)
display.setCurrent(f3);
else if(c==4)
c=0;
try{
Thread.sleep(1500);
}
catch(Exception e){
}
}
}

slide show image

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

public class SlideShowImage extends MIDlet implements CommandListener


{

private Display display;


private Form f1,f2,f3;
private Command exit;
private Image i1,i2,i3;
private ImageItem it1,it2,it3;
public SlideShowImage()

{
display=Display.getDisplay(this);
exit=new Command("EXIT",Command.EXIT,1);
try{
i1=Image.createImage("/index1.png");
i2=Image.createImage("/index2.png");
i3=Image.createImage("/index3.png");

it1=new ImageItem("p1",i1,ImageItem.LAYOUT_DEFAULT,"unable");
it2=new ImageItem("p2",i2,ImageItem.LAYOUT_DEFAULT,"unable");
it3=new ImageItem("p3",i3,ImageItem.LAYOUT_DEFAULT,"unable");
f1=new Form("first form");

f1.append(i1);

f2=new Form("second form");


f2.append(i2);

f3=new Form("third form");


f3.append(i3);

f1.addCommand(exit);
f2.addCommand(exit);
f3.addCommand(exit);

f1.setCommandListener(this);
f2.setCommandListener(this);
f3.setCommandListener(this);}

catch(java.io.IOException error){
Alert alert=new Alert("error","cannot find",null,null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
} }
public void startApp()
{
Thread runner=new Thread(new ThreadRunner(display,f1,f2,f3));
runner.start();
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{

}
public void commandAction(Command c,Displayable display){

if(c==exit)
{
destroyApp(true);
notifyDestroyed();
}

}
class ThreadRunner implements Runnable{
Display display;
int c=0;
Form f1,f2,f3;
public ThreadRunner(Display display,Form f1,Form f2,Form f3){
this.display=display;
this.f1=f1;
this.f2=f2;
this.f3=f3;
}
public void run(){
while(true){
c++;
if(c==1)
display.setCurrent(f1);
else if(c==2)
display.setCurrent(f2);
else if(c==3)
display.setCurrent(f3);
else if(c==4)
c=0;
try{
Thread.sleep(1500);
}
catch(Exception e){
}
}
}
}
}

You might also like