Ady Wicaksono Daily Activities

When will your SBS Transit Bus arrive, check on your mobile phone?

with 3 comments

Previously I create an Iris next bus application using perl, now I create a J2ME application so you can now access Iris next bus using your mobile phone, everywhere, everytime, no matter what operator you use as long as you have access to GPRS network.

Why? Because I need it and I want to make it cheap service. How it works? Simply see the application on my Nokia N73.

1. Step 1, input your bus number and bus stop number
fescr000.jpg

2. Get the information

fescr001.jpg

fescr002.jpg

So, here is the J2ME source code, it’s very simple, dummy code, no such optimization, the I/O network is blocking, but it’s all that I need.


// Simple IRIS Next Bus Application
// version 0.1 2/26/2008
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class irisnextbus extends MIDlet  implements CommandListener{

     private Display display;
     private Command openCmd =
	   new Command("Check Sched.",Command.OK,1);
     private Command exitCmd =
	   new Command("Exit",Command.EXIT,2);
     private Command backCmd =
	   new Command("Back",Command.EXIT,2);

     private Form f, f2;
     private TextField t1, t2;
     private Alert a1;

     public  irisnextbus(){}

     public void startApp(){
        display    = Display.getDisplay(this);
		f          = new Form("IRIS next bus");
        t1         = new TextField("Bus Number","",4,TextField.NUMERIC);
        t2         = new TextField("Bus Stop Number","",5,TextField.NUMERIC);
		f.append(t1);
		f.append(t2);

		f.addCommand(openCmd);
		f.addCommand(exitCmd);
		f.setCommandListener(this);
		display.setCurrent(f);
     }

     public void checkSched(){
	     openSched();
     }

     public void openSched(){
     	 HttpConnection c = null;
         InputStream is   = null;
         String url2open;
		 int responsecode;
		 int ch;

		 if(t1.getString().trim().equals("") || t2.getString().trim().equals("")){

		 }else{
			 StringBuffer info = new StringBuffer("");
	     	try{
	           url2open = "http://202.147.193.229/iris/next.cgi?b1=" +
				         t1.getString().trim() + "&b2=" + t2.getString().trim();
	     	   c  = (HttpConnection)Connector.open(url2open.trim());
			   c.setRequestMethod(HttpConnection.GET);
			   is = c.openInputStream();
		       responsecode = c.getResponseCode();
			   String str   = null;
		   	   if(responsecode == 200){
					int length = (int) c.getLength();
					if (length != -1){
						byte incomingData[] = new byte[length];
						is.read(incomingData);
						str = new String(incomingData);
					}else{
						ByteArrayOutputStream bytestream =
							  new ByteArrayOutputStream();

						while ((ch = is.read()) != -1)
						{
						  bytestream.write(ch);
						}
						str = new String(bytestream.toByteArray());
						bytestream.close();
					}
					display.setCurrent(new Alert("Info",
					str,null,AlertType.INFO),f);
		       }
	     	}catch(IOException e){

	     	}finally{
				try{
				   if (is != null){
						 is.close();
				   }
				   if (c != null){
						 c.close();
				   }	

				}catch(Exception e){}
			}
	     }
     }  	 

	 public void exitApp(){
        destroyApp(true);
     }

     public void commandAction(Command c, Displayable d){
	    String lbl = c.getLabel();
		if(lbl.equals("Exit")){
		   exitApp();
		}else if(lbl.equals("Check Sched.")){
		   checkSched();
		}else if(lbl.equals("Back")){
			display.setCurrent(f);
		}
     }

	 public void pauseApp() {
	 }

	 public void destroyApp(boolean unconditional){
	    notifyDestroyed();
     }
}

Written by adywicaksono

February 26, 2008 at 6:13 pm

Posted in j2me

3 Responses

Subscribe to comments with RSS.

  1. kenapa N73… Eseries dong :p

    Hedwig™

    March 17, 2008 at 8:52 am

  2. Iya Di…buat E51 dongs….

    thanks

    Joko

    chicken

    May 11, 2008 at 3:43 pm

  3. Hi,

    Interesting! I am implementing J2ME message-based app. I am looking for your advise. Do you know how to enable the delivery report for WMA 2.0 protocol. There is no API set for it? That’s bad as the interaction is very important. Workaround (kind of send ACK when timeout from server) is not applicable in my case. I need a delivery report from MSCC.

    Hope to hear from you,

    Hans

    July 21, 2008 at 6:49 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: