import javax.microedition.io.Connector; import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; import javax.wireless.messaging.MessageConnection; import javax.wireless.messaging.TextMessage; public class kirimSMS extends MIDlet implements CommandListener,Runnable { private Form sendMessageForm; private TextField number, msg; private Command cmdOK,cmdExit; private String telpNum, isiPesan = ""; public SendMidlet(){ cmdExit = new Command("Back", Command.EXIT, 2); cmdOK = new Command("Send", Command.SCREEN, 2); sendMessageForm = new Form("Send Message"); msg = new TextField("Message:", null, 50, TextField.ANY); number = new TextField("Telepon:", null, 15, TextField.PHONENUMBER); sendMessageForm.append(number); sendMessageForm.append(msg); sendMessageForm.addCommand(cmdOK); sendMessageForm.addCommand(cmdExit); sendMessageForm.setCommandListener(this); } protected void destroyApp(boolean arg0) { notifyDestroyed(); } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(sendMessageForm); } public void commandAction(Command arg0, Displayable arg1) { if(arg0==cmdOK){ telpNum = number.getString(); isiPesan = msg.getString(); new Thread(this).start(); number.setString(""); msg.setString(""); Display.getDisplay(this).setCurrent(sendMessageForm); }else if(arg0==cmdExit){ destroyApp(true); } } public void run() { try{ String nomorTelp = "sms://" + telpNum + ":1234"; MessageConnection conn = (MessageConnection)Connector.open(nomorTelp); TextMessage msg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE); msg.setPayloadText(isiPesan); conn.send(msg); conn.close(); }catch(Exception e){ e.printStackTrace(); } } }
Tidak ada postingan.
Tidak ada postingan.