// ITU F2005 JMA - Homework week 02 // Exercise2.java // 2005-02-15 Kenn A. Thisted /* * Program a simple SMS sender that allows the user to create a SMS message in * the display of the mobile device (hint: use a Textbox or Textfield object). * Make a "Send" button that prints the message in the console area of the * toolkit when the "Send" button is activated. */ /* * Related links: * http://www.gsm-technology.com/gsm.php/en,unlock,subpage_id,smsfaq.html (*) * http://java.sun.com/j2me/docs/wtk2.1/user_html/wma.html * http://www.wirelessdevnet.com/channels/java/features/simplewire/ */ import javax.microedition.midlet.MIDlet; import javax.microedition.lcdui.*; public class Exercise2 extends MIDlet implements CommandListener { private Display display; private TextBox smsMessage; static final Command sendCommand = new Command ("Send", Command.SCREEN, 1); static final Command exitCommand = new Command ("Exit", Command.STOP, 2); public Exercise2() { } public void startApp() { display = Display.getDisplay(this); // 160 characters for text messaging transport (7-bit ASCII). (*) smsMessage = new TextBox("Enter SMS Message", null, 160, 0); smsMessage.addCommand(sendCommand); smsMessage.addCommand(exitCommand); smsMessage.setCommandListener(this); display.setCurrent(smsMessage); } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { if (c == sendCommand) { System.out.println("SMS message: " + smsMessage.getString()); } else { destroyApp(true); } } // commandAction() }