Kjava林林工具箱源代码(jbuilder工程) 博客分类: 游戏 JBuilder百度游戏金融交通
程序员文章站
2024-02-18 12:39:52
...
j2me源代码,一个用jbuilder开发的手机便民工具箱的项目。
jbuilder 2005 + wtk2.5
给大家共享一下。一起学习。
项目只能用于学习,限用于商业用途。
源代码分析:
MobileMIDlet启动服务
在上面MIDLet里,启动了canvas MobileMainCanvas,由它来负责画界面。
jbuilder 2005 + wtk2.5
给大家共享一下。一起学习。
项目只能用于学习,限用于商业用途。
源代码分析:
MobileMIDlet启动服务
package cn.mobell.windows; import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; import java.io.IOException; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import java.util.Vector; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.ByteArrayInputStream; import cn.mobell.tool.WmlParser; import cn.mobell.tool.HttpData; import cn.mobell.tool.ThreaHttp; /** * * <p> * Title: 主 MIDlet * </p> * <p> * Description: 项目只能用于学习,限用于商业用途。 * </p> * * <p> * Copyright: Copyright (c) 2008 - 06 * </p> * * <p> * Company: * </p> * * @author atgongguoat@163.com * @version 1.0 */ public class MobileMIDlet extends MIDlet implements CommandListener { private Display display; MobileMainCanvas initCanvas_temp; //联网线程(2008-12-24) // private ThreaHttp httpThread; public MobileMIDlet() { HttpData.getInstance().readTimeTest("readTimeTest"); display = Display.getDisplay(this); //启动联网线程 // httpThread = new ThreaHttp(); // this.startMidThrea(); initCanvas_temp = new MobileMainCanvas(this); initCanvas_temp.game_start(); display.setCurrent(initCanvas_temp); } public void pauseApp() { //notify(); } public void startApp() { } public void exit() { initCanvas_temp.game_stop(); Display.getDisplay(this).setCurrent(null); destroyApp(true); } //传入参数true public void destroyApp(boolean parm1) { notifyDestroyed(); } public void commandAction(Command command, Displayable displayable) { } // /** // * 启动联网(测试) // */ // private void startMidThrea() { // try { // httpThread.startThreaHttp(); // httpThread.initHttp("http://wap.mobell.cn/wendao/wendaolist.php?kjava=1&word=%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%B0%E7%90%83%E4%B8%8D%E6%98%AF%E5%9C%86%E7%9A%84&dosubmit=dosubmit", "init"); // } catch (Exception exe) { // exe.printStackTrace(); // } // } // /** // * 初始化联网参数 // * @param wapurl String 访问URL // * @param datatype String 存贮数据键值 (key) // */ // public void initHttp(String wapurl, String datatype) { // httpThread.wapurl = wapurl; // httpThread.datatype = datatype; // httpThread.isrun = true; // } }
在上面MIDLet里,启动了canvas MobileMainCanvas,由它来负责画界面。
package cn.mobell.windows; import java.util.Vector; import javax.microedition.lcdui.*; import cn.mobell.port.abstractCanvas; import cn.mobell.ui.MyTextBox; import cn.mobell.ui.MyList; import cn.mobell.ui.MyChoiseGroup; import cn.mobell.tool.*; import cn.mobell.ui.Mytextshow; import java.io.*; public final class MobileMainCanvas extends abstractCanvas implements Runnable, CommandListener { public MobileMainCanvas() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } MobileInfo mobileInfo; private MobileMIDlet midlet; public Thread gameThread; MyTextBox textbox; MyList mylist; Mytextshow textshow; // MyChoiseGroup choiseGroup1; // MyChoiseGroup choiseGroup2; boolean showIs = false; private boolean httpcatoonbool = false; String temptextshow; //////////////九宫菜单////////////// private Image icons[] = new Image[9]; private int nrow = 3; private int ncol = 3; private int imgNum = 0; private int[] pointX = new int[9]; private int[] pointY = new int[9]; //////////////九宫菜单////////////// //Font.SIZE_SMALL); //保存系统字型 /////////////屏幕坐标////////////// // private int title_x; //标题坐标 // private int title_y = 2; private int ticker_x = 0; //滚动条坐标 private int ticker_y = 47; private int text_x = 0; //文本坐标 private int text_y = 75; private int table_x; //下拉框坐标 private int table_y = 31; /////////////屏幕坐标////////////// // Command okcommand = new Command("确定", Command.SCREEN, 1); //非游戏图片以及片头动画变量 private Image loadres; private Image[] loadImage = new Image[4]; private Image arrowImage; private Image logoImage; private Image bgImage; private Image bgtopImage; private Image bgfootImage; private Image buttemImage; private Image selectImage; private Image listselectImage; private Image menuImage; private Image arrawLImage; private Image arrawRImage; private Image arrawPImage; private int timeCount; //计数器 private int timeid; //计数器 private int keydelay = 0; //用来控制按键时的延迟时间 private boolean key_press = false; //立即按键,快速执行 private boolean keyRepeat; //控制按键 private int key; //键值 //游戏屏幕的宽度和高度-非全屏模式 private final int WIDTH = 240; private final int HEIGHT = 320; private final int TIME_PER_FRAME = 80; //游戏速度的控制 /* about variable of game state */ public int game_state; private static final int P_LOAD = 0; //游戏最先进入的状态 private static final int P_MENU = 1; private static final int P_TABLEFORM = 2; private static final int P_EXIT = 9; private static final int P_LOADER = 10; private boolean quitGame = false; //游戏结束 /////////////tableForm////////// private int tickerStepX; //ticker滚动条 x 变量 //标题 宽度和高度 int table_state; private static final int TABLEFORM_LIST = 0; private static final int TABLEFORM_INPUT = 1; private static final int TABLEFORM_SHOW = 2; //TabbarNames数组 宽度和高度 根据背景图片设定 private int tabbarStarX; //TabbarNames数组 菜单初始 X 坐标 private int tabbarStarY; //TabbarNames数组 菜单初始 Y 坐标 private int tabbarEndX; //TabbarNames数组 菜单结束 X 坐标 private int tabbarEndY; //TabbarNames数组 菜单结束 Y 坐标 private int tabbarStepX = 0; //TabbarNames数组 table 偏移坐标 private int bgstepX; //TabbarNames数组 table 偏移量 private int strstepX; //TabbarNames数组 table 偏移量 private int tabbarStateid; private int tabbarStateUPid; private int[] tabbarX = new int[9]; //TabbarNames数组 菜单初始 X 坐标 private int listId; // boolean lightID = false; /////////////tableForm////////// /////////////textshow////////// int rowid; //要显示的文本行数长度 int showId; //超出的行数 int line; //可显示的行数 /////////////textshow////////// /******************************/ /******* 联网动画数据定义 ****/ /******************************/ private Image httpImage; private Image[] httpLoadImage = new Image[4]; private int urltimeCount ; public MobileMainCanvas(MobileMIDlet MID) { this.midlet = MID; game_init(); display = Display.getDisplay(midlet); this.setFullScreenMode(true); //联网线程 初始化及启动 ThreaHttp.getInstance().startThreaHttp(); } // 游戏初始化 private final void game_init() { // logoImage = loadImage("/bglogo.png"); // loadres = loadImage("/loading.png"); for (int i = 0; i < 4; i++) { loadImage[i] = Image.createImage(loadres, 0, i * 15, 145, 15, 0); } /******************************/ /******* 联网图片初始化 ****/ /******************************/ httpImage = loadImage("/urlloading.png"); for (int i = 0; i < 4; i++) { httpLoadImage[i] = Image.createImage(httpImage, 0, i * 11, 10, 10, 0); } /****************************/ bgImage = loadImage("/bg.png"); bgtopImage = Image.createImage(bgImage, 0, 0, 240, 47, 0); bgfootImage = Image.createImage(bgImage, 0, 48, 232, 20, 0); buttemImage = Image.createImage(bgImage, 0, 70, 70, 20, 0); // selectImage = loadImage("/select.png"); listselectImage = loadImage("/listselect.png"); /** * 载入图片。切割图片资源 */ //切割9宫菜单 menuImage = loadImage("/menu.png"); for (int i = 0; i < 9; i++) { icons[i] = Image.createImage(menuImage, 0 + i * 75, 0, 75, 76, 0); } // arrowImage = loadImage("/arrow.png"); arrawLImage = Image.createImage(arrowImage, 0, 12, 4, 7, 0); arrawRImage = Image.createImage(arrowImage, 5, 12, 4, 7, 0); arrawPImage = Image.createImage(arrowImage, 0, 0, 12, 11, 0); bgstepX = 4 * stepFontHight; for (int r = 0; r < nrow; r++) { for (int c = 0; c < ncol; c++) { imgNum = r * 3 + c; pointX[imgNum] = 5 + (77) * r; pointY[imgNum] = 60 + (77) * c; } } tabbarStarX = 12; tabbarStarY = 30; tabbarEndX = WIDTH - 2 * tabbarStarX; tabbarEndY = 53; bgstepX = 70; strstepX = 0; for (int i = 0; i < tabbarX.length; i++) { tabbarX[i] = tabbarStarX + (70 - samllfont.stringWidth("开始开始")) / 2 + bgstepX * i; } mobileInfo = new MobileInfo(); line = screen_height / stepFontHight; } //开始线程 public final void game_start() { gameThread = new Thread(this); gameThread.start(); } public final void game_stop() { gameThread = null; System.gc(); } protected final void paint(Graphics g) { g.setFont(samllfont); try { switch (game_state) { case P_LOAD: //最先进入得画面,显示loading画面 drawLoading(g, HEIGHT - 30); break; case P_MENU: // 进入九宫画面 drawBG(g); paintMenu(g); // paintTicker(g, System.getProperty("microedition.platform")); paintTicker(g, System.getProperty("microedition.platform")); break; case P_EXIT: paintTicker(g, "退出工具箱,您确定?"); break; case P_TABLEFORM: // 进入TableForm画面 drawBG(g); drawTableFormTabbar(g); switch (table_state) { case TABLEFORM_LIST: paintTicker(g, "菜单列表页面"); drawTableFormList(g); break; case TABLEFORM_INPUT: paintTicker(g, mobileInfo.getTabbar(tabbarStateid)[listId]); switch (tabbarStateid) { case 0: //百度 switch (listId) { case 0: //百宝知道 case 1: //百宝百科 case 2: //百宝英汉 case 3: //百宝汉英 case 4: //全文翻译 textbox.paint(g); break; } break; case 1: //金融 switch (listId) { case 0: //大盘行情 break; case 1: //个股查询 textbox.paint(g); break; case 2: //基金查询 textbox.paint(g); break; case 3: //外汇价格 // mylist.paint(g); break; } break; case 2://彩票 switch (listId) { case 0: //体彩 mylist.paint(g); break; case 1: //* break; } case 3: //生活娱乐 break; case 4: //交通出行 textbox.paint(g); String[] temp_title = {"线路查询", "站点查询", "换乘查询"}; //联网取标题数据 drawList(g, temp_title, 20); break; case 5: //生活工具 switch (listId) { case 1: // 常用号码 break; case 0: // case 2: // case 3: // case 4: // case 5: // textbox.paint(g); break; } break; case 6: //星座 switch (listId) { case 0: // 奇异梦解 textbox.paint(g); break; case 1: //每日星运 break; } break; case 7: //3G快车 break; case 8: //在线帮助 break; } break; case TABLEFORM_SHOW: paintTicker(g, "查询结果信息"); switch (tabbarStateid) { case 0: //百度 switch (listId) { case 0: //百宝知道 mylist.paint(g); break; case 1: //百宝百科 case 2: //百宝英汉 case 3: //百宝汉英 case 4: //全文翻译 textshow.paint(g); break; } break; case 1: //金融 switch (listId) { case 0: //大盘行情 //直接联网显示大盘行情 显示深市沪市行情 textshow.paint(g); break; case 1: //个股查询 case 2: //基金查询 textshow.paint(g); break; case 3: //外汇价格 break; } break; case 2: //彩票查询 switch (listId) { case 0: // 体彩 break; case 1: //* textshow.paint(g); break; } break; case 3: //生活娱乐 textshow.paint(g); break; case 4: //交通出行 switch (listId) { case 0: //公交查询 break; case 1: //火车查询 mylist.paint(g); break; case 2: //飞机查询 mylist.paint(g); break; } break; case 5: textshow.paint(g); break; case 6: textshow.paint(g); break; case 7: textshow.paint(g); break; case 8: textshow.paint(g); break; } //drawTextShow(g, wmlinfo_text); break; } break; case P_LOADER: paintloader(g); break; } } catch (Exception e) { long timenow = System.currentTimeMillis(); while (System.currentTimeMillis() - timenow < 10000) { //10秒后退出 } quitGame = true; } } //测试用 boolean cartoonboolean = false; public final void run() { long starttime = 0; long timetaken = 0; try { while (!quitGame) { starttime = System.currentTimeMillis(); urltimeCount++; switch (game_state) { case P_EXIT: break; case P_LOAD: if (timeCount >= 23) { timeid = -1; } else if (timeCount <= 0) { timeid = 1; } timeCount = timeCount + timeid; if (timeCount >= 23) { imgNum = 0; game_state = P_MENU; } // // 联网数据处理结束 // // 取到初始数据结束 // if (HttpData.userHash.containsKey("init")) { // //清除 联网 数据 // HttpData.userHash.remove("init"); // game_state = P_MENU; // // 速度测试 //// cn.mobell.tool.HttpData.getInstance().readTimeTest("初始数据结束"); // // } break; case P_MENU: tickerStepX++; if (tickerStepX > WIDTH) { tickerStepX = 0; } break; case P_TABLEFORM: break; case P_LOADER: timeCount++; if (timeCount > loaderw) { timeCount = 0; } break; } repaint(); serviceRepaints(); if (keydelay > 0) { //按键时间控制 keydelay--; } //垃圾回收 System.gc(); timetaken = System.currentTimeMillis() - starttime; if (timetaken < TIME_PER_FRAME) //确定游戏帧数 gameThread.sleep(TIME_PER_FRAME - timetaken); // if(cartoonboolean){ // System.out.println("^^^^^^^^^^^^^^^^^^^^^"); // httpcatoonbool = true; // } } } catch (Exception ex) { repaint(); serviceRepaints(); } } /** *连续按键控制 * * */ protected void keyRepeated(int keyCode) { keyPressed(keyCode); } /** *按键控制 * 所有主线程中按键控制 * */ protected final void keyPressed(int keycode) { // key_press = true; this.key = keycode; if (keydelay == 0) { keydelay = 3; switch (game_state) { case P_EXIT: if (key == KEY_SOFTKEY1) { quitGame = true; midlet.exit(); } if (key == KEY_SOFTKEY2) { game_state = P_MENU; } break; case P_MENU: keyProcessMenu(); break; case P_TABLEFORM: keyProcessTableForm(); switch (table_state) { case TABLEFORM_LIST: keyProcessTableForm_list(); break; case TABLEFORM_INPUT: keyProcessTableForm_input(); break; case TABLEFORM_SHOW: keyProcessTableForm_show(); break; } break; } } } /** *键释放 * * */ protected final void keyReleased(int keycode) { // keyRepeat = false; this.key = 0; } /** *重画 * * */ public final void repaintFrame(int time) { long PaintTime = System.currentTimeMillis(); repaint(); serviceRepaints(); PaintTime = System.currentTimeMillis() - PaintTime; try { if (PaintTime < time) Thread.sleep(time - PaintTime); else Thread.sleep(0); } catch (Exception ex) { } } ////来电 protected void hideNotify() { } protected void showNotify() { } /** *程序启动时,开机动画 *posY 动画显示的Y坐标 * */ private void drawLoading(Graphics g, int posY) { g.setColor(0xffffff); g.fillRect(0, 100, WIDTH, HEIGHT); g.drawImage(logoImage, (WIDTH - logoImage.getWidth()) >> 1, (HEIGHT - logoImage.getHeight()) / 2, 20); g.drawImage(loadImage[timeCount % 3], (WIDTH - loadImage[timeCount % 3].getWidth()) >> 1, 178, 20); } /******************************/ /******* 画联网数据处理动画 *****/ /******************************/ public void setHttpcatoonbool(boolean _httpcatoonbool){ this.httpcatoonbool = _httpcatoonbool; } private void drawHttpCatoon(Graphics g ) { g.setClip(0,0,240,320); if(httpcatoonbool){ int httpcount = (urltimeCount / 4) % 4; System.out.println("httpcount = " + httpcount); g.drawImage(httpLoadImage[httpcount], WIDTH - httpLoadImage[httpcount].getWidth()-10, 10, 20); System.out.println("ddddddddddddddddddddddddddd = " + httpcount); } } //画载入 int loaderx = 67; int loadery = HEIGHT - 26; int loaderw = 242; int loaderh = 26; int loadertempx = 26; private void paintloader(Graphics g) { g.setColor(0xffffff); g.fillRect(loaderx, loadery, timeCount, loaderh); } /** *统一背景 * * */ private void drawBG(Graphics g) { g.setColor(0xFFFFFF); g.fillRect(0, 0, WIDTH, HEIGHT); g.drawImage(bgtopImage, 0, 0, 20); g.drawImage(bgfootImage, (WIDTH - bgfootImage.getWidth()) >> 1, HEIGHT - bgfootImage.getHeight(), 20); g.drawString("确定", 10, 302, 20); g.drawString("返回", 202, 302, 20); // drawHttpCatoon(g); // g.drawImage(buttemImage, 0, // HEIGHT - buttemImage.getHeight(), 20); // g.drawImage(buttemImage, (WIDTH - buttemImage.getWidth()) , // HEIGHT - buttemImage.getHeight(), 20); } /** * 画九宫菜单 * */ private void paintMenu(Graphics g) { for (int r = 0; r < nrow; r++) { for (int c = 0; c < ncol; c++) { // g.drawImage(icons[r * 3 + c], pointX[r * 3 + c], pointY[r * 3 + c], 20); } } g.drawImage(selectImage, pointX[imgNum] + 12, pointY[imgNum] + 27, 20); } /** * 画滚动条菜单 * str 所要显示的文字 * stringLong 所显示文字的长度,当stringLong大于屏幕宽度时,滚动,否则居中 */ private void paintTicker(Graphics g, String str) { int stringLong = samllfont.stringWidth(str); g.setColor(0x000000); g.setClip(0, 29, WIDTH, HEIGHT); if (stringLong < WIDTH) { ticker_x = (WIDTH - stringLong) / 2; } else { ticker_x = WIDTH / 2 - tickerStepX; } g.drawString(str, ticker_x, ticker_y, 20); } /** * 画TableForm 通用背景 * * */ private void drawTableFormTabbar(Graphics g) { //画Tablebar工具条中 左右图标 g.drawImage(arrawLImage, 0, table_y, 20); g.drawImage(arrawRImage, WIDTH - arrawRImage.getWidth(), table_y, 20); g.setClip(tabbarStarX, tabbarStarY, tabbarEndX, tabbarEndY); //画Tablebar工具条 tabbarStateUPid = tabbarStateid; if (tabbarStateid > 8) { tabbarStateUPid = 0; } else if (tabbarStateid < 0) { tabbarStateUPid = 8; } g.drawImage(buttemImage, tabbarStarX + tabbarStepX, 24, 20); //画Tablebar工具条中菜单 g.setColor(0xffffff); for (int i = 0; i < mobileInfo.TabbarNames.length; i++) { g.drawString(mobileInfo.TabbarNames[i], tabbarX[i], 30, 20); } if (tabbarStateid == tabbarStateUPid) { g.setColor(0x000000); g.drawString(mobileInfo.TabbarNames[tabbarStateUPid], tabbarX[tabbarStateUPid], 30, 20); } } /** * //画TableForm List菜单 * * */ protected void drawTableFormList(Graphics g) { int y = 75; int setpy = 26; g.setClip(0, 0, WIDTH, HEIGHT); g.drawImage(listselectImage, 0, y + setpy * (listId) - 3, 20); g.setColor(0x000000); for (int i = 0; i < mobileInfo.getTabbar(tabbarStateid).length; i++) { g.drawImage(arrawPImage, 5, y + setpy * (i), 20); g.drawString(mobileInfo.getTabbar(tabbarStateid)[i], 27, y + setpy * (i), 20); } } /** * ////画list页面查询菜单 * * */ protected void drawList(Graphics g, String[] str, int y) { g.setClip(0, 0, WIDTH, HEIGHT); g.setColor(0x000000); for (int i = 0; i < str.length; i++) { g.drawString(str[i], 3, text_y + y + stepFontHight * (i), 20); } } /** * 九宫菜单页面按键控制 * * */ private void keyProcessMenu() { if (key == KEY_UP_ARROW) { imgNum--; if (imgNum < 0) { imgNum = 8; } } if (key == KEY_DOWN_ARROW) { imgNum++; if (imgNum > 8) { imgNum = 0; } } if (key == KEY_LEFT_ARROW) { if (imgNum != 2 && imgNum != 1) { imgNum = imgNum - 3; if (imgNum < 0) { imgNum = 8; } } else imgNum = imgNum + 5; } if (key == KEY_RIGHT_ARROW) { if (imgNum != 6 && imgNum != 7) { imgNum = imgNum + 3; if (imgNum > 8) { imgNum = 0; } } else imgNum = imgNum - 5; } if (key == KEY_SOFTKEY1 || key == KEY_SOFTKEY3) { game_state = P_TABLEFORM; table_state = TABLEFORM_LIST; } if (key == KEY_SOFTKEY2) { game_state = P_EXIT; } } /** * TableForm 页面 左右选择时 按键控制 * 优先级最大 * */ private void keyProcessTableForm() { if (key == KEY_LEFT_ARROW) { table_state = TABLEFORM_LIST; listId = 0; tabbarStateid--; if (tabbarStateid < 0) { tabbarStateid = 8; } tabbarStepX = tabbarStepX - bgstepX; if (tabbarStarX + tabbarStepX <= 0) { tabbarStepX = 0; int vvv; vvv = tabbarX[8]; tabbarX[8] = tabbarX[0]; tabbarX[0] = tabbarX[1]; tabbarX[1] = tabbarX[2]; tabbarX[2] = tabbarX[3]; tabbarX[3] = tabbarX[4]; tabbarX[4] = tabbarX[5]; tabbarX[5] = tabbarX[6]; tabbarX[6] = tabbarX[7]; tabbarX[7] = vvv; } } if (key == KEY_RIGHT_ARROW) { table_state = TABLEFORM_LIST; listId = 0; tabbarStateid++; if (tabbarStateid > 8) { tabbarStateid = 0; } tabbarStepX = tabbarStepX + bgstepX; if (tabbarStepX > 2 * bgstepX) { //3 * bgstepX tabbarStepX = 2 * bgstepX; strstepX = strstepX + bgstepX; int xxx; xxx = tabbarX[0]; tabbarX[0] = tabbarX[8]; tabbarX[8] = tabbarX[7]; tabbarX[7] = tabbarX[6]; tabbarX[6] = tabbarX[5]; tabbarX[5] = tabbarX[4]; tabbarX[4] = tabbarX[3]; tabbarX[3] = tabbarX[2]; tabbarX[2] = tabbarX[1]; tabbarX[1] = xxx; } } } /** * 列表页面 按键控制 * KEY_SOFTKEY2 返回上级菜单 * * tabbarStateid 9大菜单 id * listId 9大菜单下小菜单列表 id * */ private void keyProcessTableForm_list() { if (key == KEY_UP_ARROW) { listId--; if (listId < 0) { listId = mobileInfo.getTabbar(tabbarStateid).length - 1; } } if (key == KEY_DOWN_ARROW) { listId++; if (listId > mobileInfo.getTabbar(tabbarStateid).length - 1) { listId = 0; } } if (key == KEY_SOFTKEY1 || key == KEY_SOFTKEY3) { switch (tabbarStateid) { case 0: //百度 switch (listId) { case 0: //百宝知道 case 1: //百宝百科 case 2: //百宝英汉 case 3: //百宝汉英 case 4: //全文翻译 textbox = new MyTextBox(display, this, mobileInfo.Tarry0[listId][1]); break; } table_state = TABLEFORM_INPUT; break; case 1: //金融 switch (listId) { case 0: ////大盘行情 String temp = "大盘行情"; //联网取大盘行情数据 textshow = new Mytextshow(display, this, temp); table_state = TABLEFORM_SHOW; //直接跳到页面 break; case 1: //个股查询 case 2: //基金查询 textbox = new MyTextBox(display, this, mobileInfo.Tarry1[listId][1]); table_state = TABLEFORM_INPUT; break; case 3: //外汇价格 String[][] money = (String[][])this.getLinkContent(tabbarStateid, listId, "外汇价格"); mylist = new MyList(display, this, money, midlet); table_state = TABLEFORM_INPUT; break; } break; case 2: //彩票乐透 switch (listId) { case 0: //体彩getLinkContent String[][] caipiao = (String[][])this.getLinkContent(tabbarStateid, listId, "体彩"); mylist = new MyList(display, this, caipiao, midlet); table_state = TABLEFORM_INPUT; break; case 1: //* String temp = "*行情"; //联网取*行情数据 textshow = new Mytextshow(display, this, temp); table_state = TABLEFORM_SHOW; //直接跳到页面 break; } break; case 3: //生活娱乐 break; case 4: //交通出行 switch (listId) { case 0: //公交查询 textbox = new MyTextBox(display, this, "选择城市"); table_state = TABLEFORM_INPUT; break; case 1: //火车查询 break; case 2: //飞机查询 break; } break; case 5: //生活工具 switch (listId) { case 1: // 常用号码 //getOnlyContent String temp = (String)this.getOnlyContent( tabbarStateid, listId, "常用号码");; //联网取*行情数据 textshow = new Mytextshow(display, this, temp); table_state = TABLEFORM_SHOW; //直接跳到页面 break; case 0: case 2: case 3: case 4: case 5: textbox = new MyTextBox(display, this, mobileInfo.Tarry5[listId][1]); table_state = TABLEFORM_INPUT; break; } break; case 6: switch (listId) { case 0: // 奇异梦解 textbox = new MyTextBox(display, this, mobileInfo.Tarry6[listId][1]); table_state = TABLEFORM_INPUT; break; case 1: //每日星运 String temp = "星运详情"; //联网取每日星运数据 textshow = new Mytextshow(display, this, temp); table_state = TABLEFORM_SHOW; //直接跳到页面 break; } break; case 7: //3G快车 break; case 8: //帮助 break; } } if (key == KEY_SOFTKEY2) { game_state = P_MENU; } } /** * 输入款输入字符后 按键控制 * 链接网络取得数据 然后转入 TABLEFORM_SHOW 最终显示结果页面 * tabbarStateid 9大菜单 * listId 9大菜单下小菜单列表 */ private void keyProcessTableForm_input() { if (key == KEY_SOFTKEY2) { showIs = false; table_state = TABLEFORM_LIST; } switch (tabbarStateid) { case 0: //百度 switch (listId) { case 0: //百宝知道 if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs) { //当输入框输入数据后,按左软键进行联网查询 cartoonboolean=true; String[][] biadu = (String[][])this.getMuchContent(textbox. m_text, 0, 0, "baidu"); mylist = new MyList(display, this, biadu, midlet); table_state = TABLEFORM_SHOW; cartoonboolean=false; } if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs == false) { //按确定键,输入框跳入输入界面 showIs = true; textbox.keyPress(key); } break; case 1: //百宝百科 case 2: //百宝英汉 case 3: //百宝汉英 case 4: //全文翻译 if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1)&& showIs) { String temptexbox = (String)this.getSingleContent(textbox. m_text, tabbarStateid, listId, "baoddaf"); textshow = new Mytextshow(display, displayable, temptexbox); table_state = TABLEFORM_SHOW; } if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1)&& showIs == false) { //按确定键,输入框跳入输入界面 showIs = true; textbox.keyPress(key); } break; } break; case 1://金融 switch (listId) { case 0: ////大盘行情 break; case 1: //个股查询 case 2: //基金查询 if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs) { String temptexbox = (String)this.getSingleContent(textbox. m_text,tabbarStateid, listId, "baoddaf"); textshow = new Mytextshow(display, displayable, temptexbox); table_state = TABLEFORM_SHOW; } if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs == false) { //按确定键,输入框跳入输入界面 showIs = true; textbox.keyPress(key); } break; case 3: //外汇价格 break; } break; case 2: break; case 3: break; case 4: break; case 5://生活工具 switch(listId){ case 1://常用号码 break; case 0: case 2: case 3: case 4: case 5: case 6: if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs) { String temptexbox = (String)this.getSingleContent(textbox. m_text, tabbarStateid, listId, "生活工具"); textshow = new Mytextshow(display, displayable, temptexbox); table_state = TABLEFORM_SHOW; } if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs == false) { //按确定键,输入框跳入输入界面 showIs = true; textbox.keyPress(key); } break; } break; case 6://星座 switch(listId){ case 0://解梦 if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs) { //当输入框输入数据后,按左软键进行联网查询 String[][] biadu = (String[][])this.getMuchContent(textbox. m_text, 0, 0, "baidu"); mylist = new MyList(display, this, biadu, midlet); table_state = TABLEFORM_SHOW; } if ((key == KEY_SOFTKEY3 || key == KEY_SOFTKEY1) && showIs == false) { //按确定键,输入框跳入输入界面 showIs = true; textbox.keyPress(key); } break; case 1: break; } break; case 7: break; case 8: break; } } /** * 最终文本显示页面 按键控制 * KEY_SOFTKEY2 返回上级菜单 * * 当文字的长度大于一屏时;通过上下按键翻滚页面 * tabbarStateid 9大菜单 * listId 9大菜单下小菜单列表 * rowid 联网取得的文本的行数 * line 一屏可显示的行数 */ private void keyProcessTableForm_show() { if (key == KEY_SOFTKEY2) { showIs = false; if(tabbarStateid == 0){ table_state = TABLEFORM_INPUT; }else { table_state = TABLEFORM_LIST; } } if (rowid > line) { if (key == KEY_UP_ARROW) { showId--; if (showId < 0) { showId = 0; } } if (key == KEY_DOWN_ARROW) { showId++; if (showId > rowid - line) { showId = rowid - line; } } } else showId = 0; switch (tabbarStateid) { case 0: //百度 if (listId==0) { //百度知道 mylist.keyPress(key); } break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6://星座 if(listId==0){//解梦 mylist.keyPress(key); } break; case 7: break; case 8: break; } } /** * 读取图片的方法 * @param read image * */ private Image loadImage(String imageName) { Image img = null; try { img = Image.createImage(imageName); } catch (Exception ex) { } return img; } public void commandAction(Command command, Displayable displayable) { } //画百度知道显示页面 public void drawHttpLoding(Graphics g) { g.drawString("联网提示", 10, HEIGHT_TEMP - 20, 20); } /** * * @param _source String 提交的文本框内容 * @param listId int 当项目id * @param _storageType String 临时存储Key * @return String 返回 无列表 内容 */ private String getSingleContent(String _source, int _tableId, int _listId, String _storageType) { // 提交中文 URL 转码 String contentStr = ""; String temptexbox = cn.mobell.tool.URLEncoder.encode(_source, "UTF-8"); String[][] array_Tarry = (String[][]) mobileInfo.getTarry(_tableId); String baiduUrl = array_Tarry[_listId][4] + "&" + array_Tarry[_listId][3] + "&" + array_Tarry[_listId][2] + "=" + temptexbox; //midlet.initHttp(baiduUrl, _storageType); ThreaHttp.getInstance().initHttp(baiduUrl, _storageType); while (true) { if (HttpData.userHash.containsKey(_storageType)) { Vector vec_data = (Vector) HttpData.userHash.get(_storageType); System.out.println("baidu vec_data.size" + vec_data.size()); for (int i = 0; i < vec_data.size(); i++) { //原来用数据类,现在用书组 //数组信息:mlTag; WXL 标签,xmlText; 内容,newline; 是否换行,pageurl; 内容对应的URL String[] wmlinfo_obj = (String[]) vec_data.elementAt(i); contentStr = contentStr + wmlinfo_obj[1]; } //清除 联网 数据 vec_data.removeAllElements(); HttpData.userHash.remove(_storageType); break; } } //自己判断无数据处理 return contentStr; } /** * * @param _source String 提交的文本框内容 * @param listId int 当项目id * @param _storageType String 临时存储Key * @return String 返回 列表 内容 */ private String[][] getMuchContent(String _source, int _tableId, int _listId, String _storageType) { // 提交中文 URL 转码 System.out.println("##$$#$启动联网动画"); String[][] contentStr = null; //标题对应的url String temptexbox = cn.mobell.tool.URLEncoder.encode(_source, "UTF-8"); String[][] array_Tarry = (String[][]) mobileInfo.getTarry(_tableId); String baiduUrl = array_Tarry[_listId][4] + "&" + array_Tarry[_listId][3] + "&" + array_Tarry[_listId][2] + "=" + temptexbox; //midlet.initHttp(baiduUrl, _storageType); ThreaHttp.getInstance().initHttp(baiduUrl, _storageType); while (true) { if (HttpData.userHash.containsKey(_storageType)) { Vector vec_data = (Vector) HttpData.userHash.get(_storageType); System.out.println("baidu vec_data.size" + vec_data.size()); contentStr = new String[vec_data.size()][2]; for (int i = 0; i < vec_data.size(); i++) { //原来用数据类,现在用书组 //数组信息:mlTag; WXL 标签,xmlText; 内容,newline; 是否换行,pageurl; 内容对应的URL String[] wmlinfo_obj = (String[]) vec_data.elementAt(i); contentStr[i][0] = wmlinfo_obj[1]; contentStr[i][1] = wmlinfo_obj[3]; } //清除 联网 数据 vec_data.removeAllElements(); HttpData.userHash.remove(_storageType); break; } } //自己判断无数据处理 //httpcatoonbool=false; return contentStr; } /** * 直接提交URL 取得数据 * @param listId int 当项目id * @param _storageType String 临时存储Key * @return String 返回 无列表 内容 */ private String getOnlyContent( int _tableId, int _listId, String _storageType) { // 提交中文 URL 转码 String contentStr = ""; String[][] array_Tarry = (String[][]) mobileInfo.getTarry(_tableId); String baiduUrl = array_Tarry[_listId][4] + "&" + array_Tarry[_listId][3] ; ThreaHttp.getInstance().initHttp(baiduUrl, _storageType); while (true) { if (HttpData.userHash.containsKey(_storageType)) { Vector vec_data = (Vector) HttpData.userHash.get(_storageType); for (int i = 0; i < vec_data.size(); i++) { //原来用数据类,现在用书组 //数组信息:mlTag; WXL 标签,xmlText; 内容,newline; 是否换行,pageurl; 内容对应的URL String[] wmlinfo_obj = (String[]) vec_data.elementAt(i); contentStr = contentStr + wmlinfo_obj[1]; } //清除 联网 数据 vec_data.removeAllElements(); HttpData.userHash.remove(_storageType); break; } } //自己判断无数据处理 return contentStr; } /** * 直接提交URL 取得数据 * @param listId int 当项目id * @param _storageType String 临时存储Key * @return String 返回 列表 内容 */ private String[][] getLinkContent( int _tableId, int _listId, String _storageType) { // 提交中文 URL 转码 String[][] contentStr = null; //标题对应的url String[][] array_Tarry = (String[][]) mobileInfo.getTarry(_tableId); String baiduUrl = array_Tarry[_listId][4] + "&" + array_Tarry[_listId][3] ; System.out.println("联网URL:"+baiduUrl); ThreaHttp.getInstance().initHttp(baiduUrl, _storageType); while (true) { if (HttpData.userHash.containsKey(_storageType)) { Vector vec_data = (Vector) HttpData.userHash.get(_storageType); System.out.println("baidu vec_data.size" + vec_data.size()); contentStr = new String[vec_data.size()][2]; for (int i = 0; i < vec_data.size(); i++) { //原来用数据类,现在用书组 //数组信息:mlTag; WXL 标签,xmlText; 内容,newline; 是否换行,pageurl; 内容对应的URL String[] wmlinfo_obj = (String[]) vec_data.elementAt(i); contentStr[i][0] = wmlinfo_obj[1]; contentStr[i][1] = wmlinfo_obj[3]; } //清除 联网 数据 vec_data.removeAllElements(); HttpData.userHash.remove(_storageType); break; } } //自己判断无数据处理 return contentStr; } private void jbInit() throws Exception { } }