Professional Documents
Culture Documents
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; /** * @author student */ public class currency extends MIDlet implements CommandListener { Form d1; TextField t1,t2,t3; Command c1,c2,c3,c4; ChoiceGroup cg,cg1; double rs; public void startApp() { String[] arr={"USD","Pounds","Yen","Euro"}; cg=new ChoiceGroup("",ChoiceGroup.EXCLUSIVE,arr,null); t1=new TextField("Rs","",10,TextField.NUMERIC); t2=new TextField("","",10,TextField.UNEDITABLE); d1=new Form("Form1"); c1=new Command("OK",Command.SCREEN,0); d1.append(t1); d1.append(cg); d1.addCommand(c1); d1.append(t2); d1.setCommandListener(this);
Display.getDisplay(this).setCurrent(d1); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c,Displayable d) { double num=Double.parseDouble(t1.getString()); if(c==c1) { if(cg.getSelectedIndex()==0) { rs=(num*0.0217); t2.setString(""+rs);
} else if(cg.getSelectedIndex()==1) { rs=(num*1.0084); t2.setString(""+rs); } else if(cg.getSelectedIndex()==2) { rs=(num*0.146); t2.setString(""+rs); } else if(cg.getSelectedIndex()==3) { rs=(num*0.0166); t2.setString(""+rs); } } }}
Program :
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Quiz extends MIDlet implements CommandListener { Display d; List L1; Form F,F1; int qcnt; int cnt; String[] opt1=new String[]{"881","888","889","880","Score is"}; String[] opt2=new String[]{"163","160","167","177"}; String[] opt3=new String[]{"21","25","22","23"}; String[] quo=new String[]{"Q1.(222/2)*8=?","Q2.55*3+2=?","Q3.(100-31)/3=?"}; Command Next=new Command("Next",Command.SCREEN,1); Command Exit=new Command("Exit",Command.EXIT,0); public Quiz(){ F=new Form("Quiz"); } public void startApp() { qcnt=0; cnt=0; F.addCommand(Next); F.setCommandListener(this); F.addCommand(Exit);F.setCommandListener(this); F.append("Click Next to Start Quiz"); d=Display.getDisplay(this); d.setCurrent(F); } public void pauseApp(){} public void destroyApp(boolean unconditional) {} public void commandAction(Command c,Displayable d1) { if(c==Exit) { destroyApp(true); notifyDestroyed(); } if(c==Next) {
if(cnt>=3) { if((L1.getSelectedIndex()+1)==4) qcnt=qcnt+1; if(qcnt==0) F1=new Form("Result:Fail"); else F1=new Form("Result:Pass"); F1.append("Score is:"+qcnt+""); F1.addCommand(Exit); F1.setCommandListener(this); d.setCurrent(F1); } else { if(cnt==0) { L1=new List(quo[0],List.EXCLUSIVE,opt1,null); } else if(cnt==1) { if((L1.getSelectedIndex()+1)==2) qcnt++; L1=new List(quo[1],List.EXCLUSIVE,opt2,null); } else { if((L1.getSelectedIndex()+1)==3) qcnt++; L1=new List (quo [2],List.EXCLUSIVE,opt3,null); } L1.addCommand(Next);L1.setCommandListener(this); L1.addCommand(Exit);L1.setCommandListener(this); cnt=cnt+1; d.setCurrent(L1); } } } }
Output :
int b=Integer.parseInt(t2.getString()); if(c==c1) { switch(cg.getSelectedIndex()) { case 0: if(t1.getString().equals("")||t2.getString().equals("")) { a1=new Alert("Alarm","Field Empty",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else if(b==0) { a1=new Alert("Alarm","Divide By Zero occurred",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else { t3.setString(""+(a+b)); } break; case 1: if(t1.getString().equals("")||t2.getString().equals("")) { a1=new Alert("Alarm","Field Empty",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else if(b==0) { a1=new Alert("Alarm","Divide By Zero occurred",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else { t3.setString(""+(a*b)); } break; case 2: if(t1.getString().equals("")||t2.getString().equals("")) {
a1=new Alert("Alarm","Field Empty",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else if(b==0) { a1=new Alert("Alarm","Divide By Zero occurred",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else { t3.setString(""+(a/b)); } break; case 3: if(t1.getString().equals("")||t2.getString().equals("")) { a1=new Alert("Alarm","Field Empty",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else if(b==0) { a1=new Alert("Alarm","Divide By Zero occurred",null,AlertType.ALARM); Display.getDisplay(this).setCurrent(a1); } else { t3.setString(""+(a-b)); } } } } }
else if(ch.getSelectedIndex()==1) ans=no1-no2; else if(ch.getSelectedIndex()==2) ans=no1/no2; else ans=no1*no2; String res=Double.toString(ans); T3.setString(res); } }
Output:
Program :
import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class Calendar extends MIDlet { public Calendar(){} public void startApp() { Form mainForm=new Form("Calendar"); mainForm.append(new DateField("Date",DateField.DATE)); Display.getDisplay(this).setCurrent(mainForm); } public void pauseApp(){} public void destroyApp(boolean unconditional){} }
Output :