Anda di halaman 1dari 5

Venchita Casuco

BSIT -ETEAAP

JavaMeAssignment
Code

MIDLet: MainMenu.java
Classes : SendSms.java
Text.java

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

/**
* @author chie
*/
public class MainMenu extends MIDlet {

public final Display display;


public MainMenu(){
display = Display.getDisplay(this);
}

public void startApp() {


checkStuff();
}

public void pauseApp() {


}

public void destroyApp(boolean unconditional) {


}
public void exit(){
destroyApp(true);
notifyDestroyed();
}
public void checkStuff(){

SendSms s = new SendSms(this);


display.setCurrent(s);
}
public void myText(SendSms newsendsms){
text s = new text(newsendsms,this);
display.setCurrent(s);

}
}

import javax.microedition.lcdui.*;
public class SendSms extends Form implements CommandListener {
MainMenu mysms;
private Display display;
private Command exit;
private Command process;
private ChoiceGroup buttons;
private int def;
private int buttonsIndex;
private Command send;
public String msg;

public SendSms(MainMenu myNewMLedger){


super(" Choice Menu ");
mysms = myNewMLedger;
buttons = new ChoiceGroup ("Gender",Choice.EXCLUSIVE);
buttons.append("Female", null);
def = buttons.append("Male", null);
buttons.setSelectedIndex(def, true);
exit = new Command("Exit",Command.EXIT, 1);
process = new Command("Process",Command.SCREEN, 2);
send = new Command("Send",Command.SCREEN,2);
buttonsIndex = append(buttons);
addCommand(exit);
addCommand(process);
setCommandListener(this);
}
public void setString(String msg)
{ def=buttons.getSelectedIndex();
msg = new String(buttons.getString(def)); }
public String getstring()
{ return msg; }
public void commandAction(Command c, Displayable s){

if (c == exit)
{
mysms.exit();
}
else if (c == process)
{
def=buttons.getSelectedIndex();
msg = new String(buttons.getString(def));
append(msg);
delete(buttonsIndex);
removeCommand(process);
addCommand(send);
} else if (c== send){ mysms.myText(this); }}}
import javax.wireless.messaging.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;

public class text extends Form implements CommandListener,Runnable {

private MainMenu SMSko;


private SendSms msgko;
private TextField msg1;
TextField number = new TextField("To:", "", 30, TextField.PHONENUMBER);
Command exit = new Command("exit",Command.EXIT,1);
Command send = new Command("send", Command.SCREEN,1);

public text(SendSms sendsms,MainMenu assignment)


{
super("Sending SMS");
SMSko= assignment;
msgko=sendsms;
msg1= new TextField("Message:",String.valueOf(msgko.getstring()),30, TextField.ANY);
append(number);
append(msg1);
addCommand(send);
addCommand(exit);
setCommandListener(this);
}
public void commandAction(Command c, Displayable s){
if(c==exit){
SMSko.exit();
}
else if (c == send) {
Thread t = new Thread(this);
t.start();
}
}
public void run(){
try{
MessageConnection conn = (MessageConnection) Connector.open("sms://"+number.getString()
+":8888");
TextMessage txt = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
txt.setPayloadText(msg1.getString());
conn.send(txt);
}
catch(Exception ex){
}
}
}

Anda mungkin juga menyukai