import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; import java.util.*; public class Lopp extends Form implements CommandListener{ Command uuesti=new Command("Uuesti", Command.SCREEN, 2); Command ok=new Command("Välju", Command.EXIT, 1); Command saadaNetti=new Command("Saada netti", Command.SCREEN, 3); StringItem olukord=new StringItem("", ""); public Lopp(boolean tulemus){ super("Mäng läbi!"); append(new StringItem((tulemus?"SINA VÕITSID!":"SINA KAOTASID!"),"")); append(olukord); addCommand(ok); addCommand(uuesti); addCommand(saadaNetti); setCommandListener(this); } public void commandAction(Command command, Displayable displayable) { if (command==ok){ JaneseMang.instance.notifyDestroyed(); } if (command==uuesti){ JaneseMang.kuvaEkraan(new M2ng()); } if(command==saadaNetti){ Saatja saatja=new Saatja(); saatja.start(); } } String teeUrliks(String tekst){ StringBuffer sb=new StringBuffer(tekst.length()); for(int i=0; i "+l.kuhu.x+", "+l.kuhu.y+"
"); } return teeUrliks(vastus.toString()); } class Saatja extends Thread{ public void run(){ HttpConnection hcon = null; DataInputStream dis = null; StringBuffer responseMessage = new StringBuffer(); String url="http://localhost:8080/examples/servlet/mobiil?author=janesemang&contents="+getTeade(); System.out.println(url); olukord.setText("Alustan saatmist .."); try{ hcon = (HttpConnection)Connector.open(url); dis = new DataInputStream(hcon.openInputStream()); int ch; while ((ch=dis.read())!=-1) { responseMessage.append((char)ch); } }catch(Exception e){ e.printStackTrace(); responseMessage.append("ERROR"); }finally{ try{ if (hcon != null) hcon.close(); if (dis != null) dis.close(); }catch (IOException ioe){ ioe.printStackTrace(); } } if (responseMessage.toString().equals("ok")){ removeCommand(saadaNetti); olukord.setText("Saadetud!"); }else{ olukord.setText("Ei suutnud saata!"); } } } }