Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hello;
- import java.io.*;
- import javax.microedition.io.*;
- import javax.microedition.lcdui.*;
- import javax.microedition.midlet.*;
- public class HelloMIDlet extends MIDlet implements CommandListener
- {
- private Display mDisplay;
- private Form mMainForm;
- private StringItem mMessageItem;
- private Command mExitCommand, mGetCommand;
- public HelloMIDlet()
- {
- mMainForm = new Form("WebClient");
- mMessageItem = new StringItem(null, "");
- mExitCommand = new Command("Exit", Command.EXIT, 0);
- mGetCommand = new Command("Get", Command.SCREEN, 0);
- mMainForm.append(mMessageItem);
- mMainForm.addCommand(mExitCommand);
- mMainForm.addCommand(mGetCommand);
- mMainForm.setCommandListener(this);
- }
- public void startApp()
- {
- mDisplay = Display.getDisplay(this);
- mDisplay.setCurrent(mMainForm);
- }
- public void pauseApp() {}
- public void destroyApp(boolean unconditional) {}
- public void commandAction(Command c, Displayable s)
- {
- if (c == mExitCommand)
- {
- notifyDestroyed();
- }
- else if (c == mGetCommand)
- {
- mMessageItem.setText("Waiting...");
- try
- {
- StreamConnection sc = (StreamConnection)Connector.open("http://ya.ru");
- InputStream is = sc.openInputStream();
- StringBuffer sb = new StringBuffer();
- int ch;
- while((ch = is.read()) != -1)
- {
- sb.append((char) ch);
- }
- mMessageItem.setText(sb.toString());
- is.close();
- sc.close();
- }
- catch (Exception ioe)
- {
- mMessageItem.setText("IOException " + ioe.toString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement