Professional Documents
Culture Documents
package hello;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;
public class HelloMIDlet extends MIDlet implements CommandListener
{
private Form form;
private Display display;
private TextField input1, input2,res;
private Command add, sub, mul,div;
private StringItem item;
public HelloMIDlet()
{
}
public void startApp()
{
display = Display.getDisplay(this);
final Form form = new Form("Calculator");
item = new StringItem("Result", "");
input1 = new TextField("First Number", "", 30, TextField.NUMERIC);
input2 = new TextField("Second Number", "", 30, TextField.NUMERIC);
res= new TextField("Result", "", 30, TextField.ANY);
form.append(input1);
form.append(input2);
form.append(res);
form.append(sub);
final StringItem mul = new StringItem("", "Mul", Item.BUTTON);
Command mulCommand = new Command("Mul command", Command.ITEM, 1);
mul.setDefaultCommand(mulCommand);
mul.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command c, Item item) {
calculate2();
}
});
form.append(mul);
final StringItem div = new StringItem("", "Div", Item.BUTTON);
Command divCommand = new Command("Div command", Command.ITEM, 1);
div.setDefaultCommand(divCommand);
div.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command c, Item item) {
calculate3();
}
});
form.append(div);
final StringItem button = new StringItem("", "Clear", Item.BUTTON);
Command buttonCommand = new Command("Button command", Command.ITEM,
1);
button.setDefaultCommand(buttonCommand);
button.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command c, Item item) {
input1.setString("");
input2.setString("");
res.setString("");
}
});
form.append(button);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() { }
public void destroyApp(boolean uncondn)
{
notifyDestroyed();
}
private void calculate()
{int one=Integer.parseInt(input1.getString());
int two= Integer.parseInt(input2.getString());
int result=one+two;
//item.setText( result + "" );
res.setString(Integer.toString(result));
}
private void calculate1()
{
int one = Integer.parseInt(input1.getString());
int two = Integer.parseInt(input2.getString());
int result = one - two;
//item.setText(result + "");
res.setString(Integer.toString(result));
}
private void calculate2()
{
int one = Integer.parseInt(input1.getString());
int two = Integer.parseInt(input2.getString());
int result = one * two;
//item.setText(result + "");
res.setString(Integer.toString(result));
}
private void calculate3()
{
int one = Integer.parseInt(input1.getString());
int two = Integer.parseInt(input2.getString());
try
{
int result = one / two;
//item.setText(result + "");
res.setString(Integer.toString(result));
}
catch(ArithmeticException e)
{
res.setString("Error");
}
}
public void commandAction(Command c, Displayable d)
{
//CALENDER:
package hello;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.TimeZone;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class HelloMIDlet extends MIDlet implements CommandListener{
private Command exit;
private ImageItem imageItem;
private Image image;
private Display display;
private Form form;
StringItem txtbut = new StringItem("", "Text", Item.BUTTON);
StringItem button,txtbutton ;
public HelloMIDlet(){
//path = "file:///C:/Users/student.admin-PC/Downloads/qqqp.png";
}
OUTPUT: