import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.rms.*; import javax.microedition.io.*; import java.io.*; import java.util.*; public class Bensukad extends MIDlet implements CommandListener{ Vector vKirjed=new Vector(); Form fMain = new Form ("Bensukad"); Form fBensukad = new Form ("Hinnad"); Form fNet = new Form ("Internet "); Form fWeb = new Form ("Hinnad"); ChoiceGroup cgPlaces = new ChoiceGroup( "Bensu hinnad", 1); Command cKaart = new Command ( "Kaart", Command.SCREEN, 1); Command cWeb = new Command ( "Internet", Command.SCREEN,1); Command cVaata = new Command ( "Vaata bensukaid", Command.SCREEN, 1); Command cMain = new Command ( "Peamenüü", Command.BACK, 1); Command cList = new Command ( "Veeb", Command.SCREEN, 1); Command cMap = new Command ( "netist -> kaardile", Command.SCREEN,1 ); Command cNaita = new Command ( "Näita kaardil", Command.SCREEN,1); Command cTagasi = new Command ( "Tagasi", Command.BACK, 1); Display disp=Display.getDisplay(this); graafika kaart=new graafika(); public Bensukad(){ kaart.posx=430; kaart.posy=230; fWeb.addCommand(cMain); fWeb.setCommandListener(this); fBensukad.append(cgPlaces); fBensukad.addCommand(cNaita); fBensukad.addCommand(cTagasi); fBensukad.setCommandListener(this); fNet.addCommand(cList); fNet.addCommand(cMap); fNet.addCommand(cMain); fNet.setCommandListener(this); fMain.append("bensukad paides koos hindadega"); fMain.addCommand(cKaart); fMain.addCommand(cWeb); fMain.setCommandListener(this); kaart.addCommand(cMain); kaart.addCommand(cVaata); kaart.setCommandListener(this); disp.setCurrent(fMain); } public void commandAction (Command command, Displayable p2) { if (command == cKaart) { disp.setCurrent(kaart); } if (command == cWeb){ disp.setCurrent(fNet); } if (command == cVaata){ disp.setCurrent(fBensukad); } if (command == cMain){ disp.setCurrent(fMain); } if (command == cList){ Veebilugeja listVeeb=new Veebilugeja(1); listVeeb.start(); } if (command == cMap){ Veebilugeja mapVeeb=new Veebilugeja(2); mapVeeb.start(); } if (command == cNaita){ int mitmes=cgPlaces.getSelectedIndex(); String[] vk = (String[]) vKirjed.elementAt(mitmes); kaart.benx=Integer.parseInt(vk[2]); kaart.beny=Integer.parseInt(vk[3]); disp.setCurrent(kaart); } if (command == cTagasi){ disp.setCurrent(kaart); } } protected void startApp() throws MIDletStateChangeException{ } protected void pauseApp( ){} protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{ } class Veebilugeja extends Thread{ String url="http://shad.dynserv.com:6060/shad/"; public String tekst=""; int mis=0; public Veebilugeja(int kuhu){ switch(kuhu){ case 1: url="http://shad.dynserv.com:6060/shad/mobla.jsp"; break; case 2: url="http://shad.dynserv.com:6060/shad/koordinaat.jsp?x="+kaart.posx+"&y="+kaart.posy; break; } mis=kuhu; } public void run(){ HttpConnection hcon = null; DataInputStream dis = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); String tekst=""; try{ hcon = (HttpConnection)Connector.open(url); dis = new DataInputStream(hcon.openInputStream()); int ch; while ((ch=dis.read())!=-1) { baos.write(ch); } byte[] b=baos.toByteArray(); tekst = new String(b); }catch(Exception e){ e.printStackTrace(); tekst=tekst+"ERROR"; }finally{ try{ if (hcon != null) hcon.close(); if (dis != null) dis.close(); }catch (Exception e){ e.printStackTrace(); } } switch (mis){ case 1: System.out.println(tekst); fWeb.append(tekst); disp.setCurrent(fWeb); break; case 2: int ajut=0; while (vKirjed.size()>0){ vKirjed.removeElementAt(0); } int lopp=0; while (true) { String[] kirjem=new String[4]; int algus = lopp + 1; lopp = tekst.indexOf(";", algus); if (lopp == -1) break; String kirje= tekst.substring((algus == 1 ? 0 : algus), lopp); int lopp2=0; int index=0; while (true) { int algus2 = lopp2 + 1; lopp2 = kirje.indexOf(":", algus2); if (lopp2 == -1) break; kirjem[index++]= kirje.substring((algus2 == 1 ? 0 : algus2), lopp2); } vKirjed.addElement(kirjem); } while(cgPlaces.size() != 0) cgPlaces.delete(0); for (int i = 0; i < vKirjed.size(); i++) { String[] s = (String[])vKirjed.elementAt(i); cgPlaces.append(s[0]+"->"+s[1],null); } disp.setCurrent(fBensukad); break; } } } } /////////////////////////graafika elemendid////////////////////// class graafika extends Canvas{ Image kaart; public int posx; //kursori public int posy; //hetkepositsioon public int benx=0, beny=0; int klaius=800; //kaardi int kkorgus=600; //suurus public graafika(){ try{kaart=Image.createImage("/kaart.png");}catch(Exception e){e.printStackTrace();} } protected void paint(Graphics g){ try{ g.drawImage(kaart, 0-posx, 0-posy, 16|4); g.setColor(255,0,0); g.drawLine((getWidth()/2)-5,getHeight()/2,(getWidth()/2)+5,getHeight()/2); g.drawLine(getWidth()/2,(getHeight()/2)-5,getWidth()/2,(getHeight()/2)+5); g.fillArc(benx-posx,beny-posy,5,5,0,360); }catch(Exception e){e.printStackTrace();} } protected void keyPressed(int kood){ if(getGameAction(kood)==Canvas.LEFT){ if (posx>getWidth()/2){posx--;} } if(getGameAction(kood)==Canvas.RIGHT){ if (posxgetHeight()/2){posy--;} } if(getGameAction(kood)==Canvas.DOWN){ if (posy