To take input, process it and Display output > Java ME Program
To take input, process it and Display output > Java ME Program
Mobile Communication and Computing
Program:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author prat
*/
public class Midlet extends MIDlet implements CommandListener{
Display d;
TextField tf;
TextField tf1;
TextField tf2;
TextField tf3;
TextField tf4;
TextField tf5;
Form f;
Form f1;
Form f2;
StringItem si;
Command next;
Command back;
Command next1;
Command back1;
public void startApp() {
d=Display.getDisplay(this);
f=new Form("Student Info");
f1=new Form("Marks");
f2=new Form("Summary");
d.setCurrent(f);
tf=new TextField("Name","",20,TextField.ANY);
tf1=new TextField("Branch","",20,TextField.ANY);
tf2=new TextField("Seat No","",20,TextField.NUMERIC);
tf3=new TextField("Physics","",20,TextField.NUMERIC);
tf4=new TextField("Chemistry","",20,TextField.NUMERIC);
tf5=new TextField("Maths","",20,TextField.NUMERIC);
si = new StringItem("Result = ", "");
f2.append(si);
f.append(tf);
f.append(tf1);
f.append(tf2);
f1.append(tf3);
f1.append(tf4);
f1.append(tf5);
next=new Command("NEXT",Command.SCREEN,0);
back=new Command("BACK",Command.SCREEN,5);
back1=new Command("BACK",Command.SCREEN,4);
next1=new Command("NEXT",Command.SCREEN,2);
f.addCommand(next);
f1.addCommand(next1);
f1.addCommand(back);
f2.addCommand(back1);
f.setCommandListener(this);
f1.setCommandListener(this);
f2.setCommandListener(this);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d1) {
// throw new UnsupportedOperationException("Not supported yet.");
if(c==next){
d.setCurrent(f1);
}
else if(c==back){
d.setCurrent(f);
}
else if(c==next1){
String a=tf3.getString();
String b=tf4.getString();
String b1=tf5.getString();
int n1=Integer.parseInt(a);
int n2=Integer.parseInt(b);
int n3=Integer.parseInt(b1);
int result=n1+n2+n3;
String name=tf.getString();
String dep=tf1.getString();
String seat=tf2.getString();
d.setCurrent(f2);
si.setText( name + " in " + dep +" Branch " + " having seat no : "+ seat+" got "+result+ " Marks in PCM ");
}
else if(c==back1){
d.setCurrent(f1);
}
}
}
Comments
Post a Comment