Advertisement
Guest User

J2ME

a guest
Aug 24th, 2011
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. package hello;
  2.  
  3. import java.io.*;
  4.  
  5. import javax.microedition.io.*;
  6. import javax.microedition.lcdui.*;
  7. import javax.microedition.midlet.*;
  8.  
  9. public class HelloMIDlet extends MIDlet implements CommandListener
  10. {
  11. private Display mDisplay;
  12. private Form mMainForm;
  13. private StringItem mMessageItem;
  14. private Command mExitCommand, mGetCommand;
  15.  
  16. public HelloMIDlet()
  17. {
  18. mMainForm = new Form("WebClient");
  19. mMessageItem = new StringItem(null, "");
  20. mExitCommand = new Command("Exit", Command.EXIT, 0);
  21. mGetCommand = new Command("Get", Command.SCREEN, 0);
  22. mMainForm.append(mMessageItem);
  23. mMainForm.addCommand(mExitCommand);
  24. mMainForm.addCommand(mGetCommand);
  25. mMainForm.setCommandListener(this);
  26. }
  27.  
  28. public void startApp()
  29. {
  30. mDisplay = Display.getDisplay(this);
  31. mDisplay.setCurrent(mMainForm);
  32. }
  33.  
  34. public void pauseApp() {}
  35.  
  36. public void destroyApp(boolean unconditional) {}
  37.  
  38. public void commandAction(Command c, Displayable s)
  39. {
  40. if (c == mExitCommand)
  41. {
  42. notifyDestroyed();
  43. }
  44. else if (c == mGetCommand)
  45. {
  46. mMessageItem.setText("Waiting...");
  47. try
  48. {
  49. StreamConnection sc = (StreamConnection)Connector.open("http://ya.ru");
  50. InputStream is = sc.openInputStream();
  51. StringBuffer sb = new StringBuffer();
  52. int ch;
  53. while((ch = is.read()) != -1)
  54. {
  55. sb.append((char) ch);
  56. }
  57. mMessageItem.setText(sb.toString());
  58. is.close();
  59. sc.close();
  60. }
  61. catch (Exception ioe)
  62. {
  63. mMessageItem.setText("IOException " + ioe.toString());
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement