public String fetchStagesData(String busno) { controller.showProgressBar(); Stages.deleteAll(); Stages.setTitle("Stages of " + busno); new Thread() { public void run() { String addloc = ""; StreamConnection c = null; InputStream s = null; StringBuffer b = new StringBuffer(); try { System.out.println("The Bus URL is " + uploadWebsite + busNos); c = (StreamConnection) Connector.open(uploadWebsite + busNos); s = c.openDataInputStream(); int ch; int k = 0; while ((ch = s.read()) != -1) { // System.out.print((char) ch); b.append((char) ch); } result = b.toString(); System.out.print(result); // String stagesString = fetchStagesData(); JSONObject ff = new JSONObject(result); String data = ff.getString("stagepts"); JSONArray jsonArray = new JSONArray(data); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonUser = jsonArray.getJSONObject(i); String lat = jsonUser.getString("lat"); String lon = jsonUser.getString("lon"); String stagename = jsonUser.getString("stagename"); Stages.append(stagename, null); System.out.println(stagename); // Location[i] = stagename; addloc = lat + "||" + lon + "~~" + addloc; } if (Stages.size() < 1) { // controller.showAlert("Entered Bus number not found", 3, AlertType.ERROR); Stages.append("Entered Bus number not found", null); Stages.removeCommand(MapStages); Stages.removeCommand(showBuses); // controller.setCurrentScreen(FormData); } else { PostionAddress = StringUtil.split(addloc, "~~"); Stages.addCommand(MapStages); Stages.addCommand(showBuses); // Stages.setCommandListener(FormData); } controller.getDisp().setCurrent(Stages); } catch (Exception e) { System.out.print(e); /* new Thread(){ public void run(){ controller.showAlert("Network Error", 3, AlertType.ERROR); } }.start();*/ controller.setCurrentScreen(FormData); new Thread() { public void run() { controller.showAlert("Error in network connection.", Alert.FOREVER, AlertType.INFO); } }.start(); } } }.start(); return result; }
public String fetchBusNoData() { busesNearMe.deleteAll(); busesNearMe.setTitle("Buses for " + Stages.getString(Stages.getSelectedIndex())); new Thread() { public void run() { String toF = ""; try { String[] tt = StringUtil.split(Stages.getString(Stages.getSelectedIndex()), " "); System.out.println("From field" + tt[0]); for (int y = 0; y < tt.length; y++) { if (y != tt.length - 1) { toF = toF + "" + tt[y] + "%20"; System.out.println("From field" + toF); } else { toF = toF + tt[y]; System.out.print("in else "); } System.out.print("Out of loop"); } System.out.print(BusNowebsite + toF); } catch (Exception e) { controller.showAlert("Network Error", 3, AlertType.ERROR); displayList(); } String addloc = ""; StreamConnection c = null; InputStream s = null; StringBuffer b = new StringBuffer(); System.out.print(BusNowebsite + toF); try { c = (StreamConnection) Connector.open(BusNowebsite + toF); s = c.openDataInputStream(); int ch; int k = 0; while ((ch = s.read()) != -1) { // System.out.print((char) ch); b.append((char) ch); } result = b.toString(); System.out.print(result); // String stagesString = fetchStagesData(); JSONObject ff1 = new JSONObject(result); String data1 = ff1.getString("routes"); JSONArray jsonArray1 = new JSONArray(data1); for (int i = 0; i < jsonArray1.length(); i++) { // JSONObject jsonUser = jsonArray1.getJSONObject(i); // String lat = jsonUser.getString ("lat"); busesNearMe.append(jsonArray1.optString(i), null); System.out.println(jsonArray1.optString(i)); } controller.getDisp().setCurrent(busesNearMe); } catch (Exception e) { System.out.print("Error " + e); // controller.getDisp().setCurrent(Stages); // controller.showAlert("Network Error", 3, AlertType.ERROR); // // controller.getDisp().setCurrent(controller.showAlert("Network Error", 3, // AlertType.ERROR), Stages); } } }.start(); controller.getDisp().setCurrent(Stages); return result; }
/** * The constructor * * @param x the x coordinate of the dialog window's top left corner * @param y the y coordinate of the dialog window's top left corner * @title dialog's title */ public FileDialog(int x, int y, int width, int height, String title) { super(x, y, width, height, true, title); _directories = new List(); _directories.setSelectable(false); _directories.setTitle("Directories"); _directories.addListener(this); _files = new List(); _files.setSelectable(false); _files.setTitle("Files"); _files.addListener(this); _fileLabel = new Label("File: "); _filterLabel = new Label("Filter: "); _fileField = new TextField(); _fileField.setText(getCurrentFileContent()); _filterField = new FilterTextField(this); _okButton = new Button("OK"); _okButton.addListener(this); _cancelButton = new Button("Cancel"); _cancelButton.addListener(this); Panel topPanel = new Panel(); GridLayoutManager topManager = new GridLayoutManager(2, 1); topPanel.setLayoutManager(topManager); topManager.addWidget(_directories, 0, 0, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); topManager.addWidget(_files, 1, 0, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); Panel bottomPanel = new Panel(); GridLayoutManager bottomManager = new GridLayoutManager(4, 4); bottomPanel.setLayoutManager(bottomManager); bottomManager.addWidget(_fileLabel, 0, 0, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_RIGHT); bottomManager.addWidget(_filterLabel, 0, 2, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_RIGHT); bottomManager.addWidget(_fileField, 1, 0, 2, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); bottomManager.addWidget(_filterField, 1, 2, 2, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); bottomManager.addWidget(_okButton, 3, 0, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); bottomManager.addWidget(_cancelButton, 3, 2, 1, 1, ALIGNMENT_CENTER, ALIGNMENT_CENTER); DefaultLayoutManager manager = (DefaultLayoutManager) getRootPanel().getLayoutManager(); manager.addWidget(topPanel, 0, 0, width - 2, height - 6, ALIGNMENT_CENTER, ALIGNMENT_CENTER); manager.addWidget(bottomPanel, 0, height - 6, width - 2, 4, ALIGNMENT_CENTER, ALIGNMENT_CENTER); fillListWidgets(getCurrentDirectory()); }