⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unicanvas.java

📁 一个图铃下载的小程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				 * sizeV = 4; sizeH = 4; posV = 1; posH = 0;
				 */
				//pageState = 1;
				if (page == PAGE_MAIN) {
					addCommand(1);
				} else {
					addCommand(2);
				}
				//myDisplay.setCurrent(this);
				break;
			case PAGE_SET:
				//System.out.println("====setList.getSelectedIndex()===="+setList.getSelectedIndex());
				if (setList.getSelectedIndex() == 0) {
					//setList.setSelectedIndex(0,true);
					setIsOpen(true);
				} else {
					//setList.setSelectedIndex(1,true);
					setIsOpen(false);
				}
				page = PAGE_MAIN;
				/*
				 * sizeV = 4; sizeH = 4; posV = 1; posH = 0;
				 */
				myDisplay.setCurrent(this);
				break;
			}
		}
	}

	public void addCommand(int flag) {
		/*removeAll();
		if (flag == 1) {
			this.addCommand(cmdExit);
			this.addCommand(cmdOK);
			this.setCommandListener(this);
		} else if (flag == 2) {
			this.addCommand(cmdBack);
			this.addCommand(cmdOK);
			this.setCommandListener(this);
		} else if (flag == 3) {
			this.addCommand(cmdBack);
			this.setCommandListener(this);
		}*/
	}

	public void removeAll() {
		/*this.removeCommand(cmdExit);
		this.removeCommand(cmdOK);
		this.removeCommand(cmdBack);*/
	}

	class LinkThread extends Thread implements Runnable {
		private volatile String url;

		//private short nextPage;

		private int operate;//1:检索目录 2:检索资源 3:检索详细信息 4:发送彩E

		public LinkThread(String url, short next, int operate) {
			this.url = url;
			//System.out.println("=======url=======" + url);
			nextPage = next;
			this.operate = operate;
			//new Thread(this).start();
		}

		public void run() {
			try {
				removeAll();
				//sleep(1000);
				if (operate == 1) {
					readCatalog(url);
				} else if (operate == 2) {
					readRes(url);
				} else if (operate == 3) {
					readPreview(url);
//					alertStr = ""+size;
//					addCommand(3);
//					nextPage = PAGE_ALERT;
				} else if (operate == 4) {
					sendMail(url);
				}
				if (operate == 3 && resultBean.getType() == 3 && nextPage != PAGE_ALERT) {
					if (glsForm == null) {
						System.out.println("=======1787=====");
						glsForm = new Form(null);
						byte[] file = resultBean.getFile();
						glsForm.setTicker(new Ticker(resultBean.getName()));
						ImageItem img = new ImageItem("", Image.createImage(file,
								0, file.length), Item.LAYOUT_CENTER, "");
						glsForm.append(img);
						glsForm.append(resultBean.getContent());
						glsForm.addCommand(cmdBack);
						glsForm.addCommand(cmdLast);
						glsForm.addCommand(cmdNext);
						glsForm.setCommandListener(canvas);
						myDisplay.setCurrent(glsForm);
					}
				}
			} catch (Exception e) {
				alertStr = "读数据出错,请重试";
				//alertStr = e.toString()+" "+test+" "+size;
				addCommand(3);
				nextPage = PAGE_ALERT;
				e.printStackTrace();
				//System.out.println("==test=="+test);
			}
			//System.out.println("=======resultVector=======" + resultVector);
			//System.out.println("=======resultBean=======" + resultBean);
			
			
			System.gc();
			linkTimes = 0;
			page = nextPage;
			//posV = 1;
		}
	}

	public void sendMail(String url) throws Exception {
		HttpConnection hc = null;
		DataInputStream in = null;

		try {
			hc = (HttpConnection) Connector.open(url);
			hc.setRequestProperty("X-Online-Host",httpMyServer);
			hc.setRequestMethod(HttpConnection.POST);
			if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
				in = new DataInputStream(hc.openDataInputStream());
				int length = in.readInt();
				if (length > 0) {
					alertStr = "发送成功";
					addCommand(3);
					nextPage = PAGE_ALERT;
				} else if (length == -1) {
					alertStr = "发送失败";
					addCommand(3);
					nextPage = PAGE_ALERT;
				}
			} else {
				alertStr = "连接失败,请重试";
				addCommand(3);
				nextPage = PAGE_ALERT;
			}
		} finally {
			if (in != null) {
				in.close();
			}
			if (hc != null) {
				hc.close();
			}
		}
	}

	public void readRes(String url) throws Exception {
		HttpConnection hc = null;
		DataInputStream in = null;
		DataOutputStream dataOut = null;
		//System.out.println("====url====="+url);
		try {
			hc = (HttpConnection) Connector.open(url);
			hc.setRequestProperty("X-Online-Host",httpMyServer);
			hc.setRequestMethod(HttpConnection.POST);
			if (mainOperate == 5) {
				dataOut = new DataOutputStream(hc.openOutputStream());
				dataOut.writeUTF(searchText.getString());
			}
			//System.out.println("==readRes===1==");
			if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
				//System.out.println("==readRes===2==");
				in = new DataInputStream(hc.openDataInputStream());
				int length = in.readInt();
				//System.out.println("=====length====="+length);
				if (length > 0) {
					curPage = in.readInt();
					totalPage = in.readInt();
					resVector = new Vector(length);
					for (int i = 0; i < length; i++) {
						ResultBean bean = new ResultBean();
						bean.setName(in.readUTF());
						
						bean.setUrl(in.readUTF());
						bean.setType(in.readInt());
						resVector.addElement(bean);
					}
					resRows = (short) resVector.size();
					if (screenRows < resRows) {
						resSizeV = screenRows;
					} else {
						resSizeV = resRows;
					}
					addCommand(2);
				} else if (length == 0) {
					alertStr = "没有符合的记录";
					addCommand(3);
					nextPage = PAGE_ALERT;
				} else if (length == -1) {
					alertStr = "读数据出错,请重试";
					addCommand(3);
					nextPage = PAGE_ALERT;
				}
			} else {
				alertStr = "连接失败,请重试";
				addCommand(3);
				nextPage = PAGE_ALERT;
			}
		} finally {
			if (in != null) {
				in.close();
			}
			if (hc != null) {
				hc.close();
			}
			if (dataOut != null) {
				dataOut.close();
			}
		}
	}

	public void readPreview(String url) throws Exception {
		HttpConnection hc = null;
		DataInputStream in = null;
		DataOutputStream dataOut = null;
		
		try {
			
			hc = (HttpConnection) Connector.open(url,Connector.READ,true);			
			hc.setRequestProperty("X-Online-Host",httpMyServer);
			//设置请求属性
			hc.setRequestMethod(HttpConnection.GET);
			
			if (mainOperate == 5) {
				dataOut = new DataOutputStream(hc.openOutputStream());
				dataOut.writeUTF(searchText.getString());
			}
			
			/*
			 * hc.setRequestProperty("IF-Modified-Since","15 Oct 2003 08:47:14
			 * GMT"); hc.setRequestProperty("User-Agent","Profile/MIDP-1.0
			 * Configuration/CLDC-1.0");
			 * hc.setRequestProperty("Content-Language","en-CA");
			 * hc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
			 * hc.setRequestProperty("Connection","Keep-Alive");
			 */

			if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
				in = new DataInputStream(hc.openDataInputStream());
				//size = (int)hc.getLength();
				int length = in.readInt();
				if (length > 0) {
					resultBean = new ResultBean();
					resultBean.setName(in.readUTF());
					resultBean.setType(in.readInt());
					//int size = in.readInt();
					//size = in.readInt();
//					byte[] len = new byte[4];
//					in.read(len);
//					int size1 = len[0];
//					int size2 = len[1];
//					int size3 = len[2];
//					int size4 = len[3];					
					
					int size1 = in.read();
					int size2 = in.read();
					int size3 = in.read();
					int size4 = in.read();			
					
//					int size1 = in.readByte();
//					int size2 = in.readByte();
//					int size3 = in.readByte();
//					int size4 = in.readByte();					
					size1 = size1>=0?size1:256+size1;
					size2 = size2>=0?size2:256+size2;
					size3 = size3>=0?size3:256+size3;
					size4 = size4>=0?size4:256+size4;
					
					size = (size1<<24) + (size2<<16) + (size3<<8)+size4;
//					System.out.println("====size====="+size);
//					System.out.println("====size1====="+size1);
//					System.out.println("====size2====="+size2);
//					System.out.println("====size3====="+size3);
//					System.out.println("====size4====="+size4);
					byte[] file = new byte[size];
					in.readFully(file);
					//in.read(file,0,size);
					resultBean.setFile(file);
					if (resultBean.getType() == 3) {
						resultBean.setContent(in.readUTF());
					} else {
						resultBean.setFileName(in.readUTF());
					}
					resultBean.setFileType(in.readUTF());
					resultBean.setLastUrl(in.readUTF());
					resultBean.setNextUrl(in.readUTF());
					//resultBean.setResID(in.readInt());
					int res1 = in.read();
					int res2 = in.read();
					int res3 = in.read();
					int res4 = in.read();
					res1 = res1>=0?res1:256+res1;
					res2 = res2>=0?res2:256+res2;
					res3 = res3>=0?res3:256+res3;
					res4 = res4>=0?res4:256+res4;
					
					int resID = (res1<<24) + (res2<<16) + (res3<<8)+res4;
					resultBean.setResID(resID);
					if (resultBean.getType() != 3) {
						addCommand(2);
					} else {
						
					}
				} else if (length == 0) {
					alertStr = "没有找到文件";
					addCommand(3);
					nextPage = PAGE_ALERT;
				} else if (length == -1) {
					alertStr = "读数据出错,请重试";
					addCommand(3);
					nextPage = PAGE_ALERT;
				}
			} else {
				alertStr = "连接失败,请重试";
				addCommand(3);
				nextPage = PAGE_ALERT;
			}
		} finally {
			if (in != null) {
				in.close();
			}
			if (hc != null) {
				hc.close();
			}
			if (dataOut != null) {
				dataOut.close();
			}
		}

	}

	public void readCatalog(String url) throws Exception {
		HttpConnection hc = null;
		DataInputStream in = null;
		//System.out.println("====url===="+url);
		try {
			hc = (HttpConnection) Connector.open(url);
			hc.setRequestProperty("X-Online-Host",httpMyServer);
			//设置请求属性
			hc.setRequestMethod(HttpConnection.POST);
			if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
				in = new DataInputStream(hc.openDataInputStream());
				int length = in.readInt();
				if (length > 0) {
					listVector = new Vector(length);
					for (int i = 0; i < length; i++) {
						ResultBean bean = new ResultBean();
						bean.setName(in.readUTF());
						bean.setUrl(in.readUTF());
						//bean.setType(in.readInt());
						//resultVector.addElement(in.readUTF());
						listVector.addElement(bean);
					}
					listRows = (short) listVector.size();
					if (screenRows < listRows) {
						listSizeV = screenRows;
					} else {
						listSizeV = listRows;
					}
					addCommand(2);
				} else if (length == 0) {
					alertStr = "没有符合的记录";
					addCommand(3);
					nextPage = PAGE_ALERT;
				} else if (length == -1) {
					alertStr = "读数据出错,请重试";
					addCommand(3);
					nextPage = PAGE_ALERT;
				}
			} else {
				alertStr = "连接失败,请重试";
				addCommand(3);
				nextPage = PAGE_ALERT;
			}
		} finally {
			if (in != null) {
				in.close();
			}
			if (hc != null) {
				hc.close();
			}
		}
	}

	//关闭或开启背景音乐
	public void setIsOpen(boolean isOpen) {
		RecordStore rs = openRS("uniClient");
		byte[] music = null;
		if (rs != null) {
			try {
				if (rs.getNumRecords() > 0) {
					music = rs.getRecord(1);
					if (isOpen) {
						music[0] = 1;
					} else {
						music[0] = 0;
					}
					rs.setRecord(1, music, 0, 1);
				} else {
					music = new byte[1];
					if (isOpen) {
						music[0] = 1;
					} else {
						music[0] = 0;
					}
					rs.addRecord(music, 0, 1);
				}
			} catch (Exception e) {
				//e.printStackTrace();
			} finally {
				closeRS(rs);
				rs = null;
				System.gc();
			}
		}
	}

	public boolean getIsOpen() {
		RecordStore rs = openRS("uniClient");
		byte[] music = null;
		if (rs != null) {
			try {
				if (rs.getNumRecords() < 1) {
					music = new byte[1];
					music[0] = 1;
					rs.addRecord(music, 0, 1);
					return true;
				} else {
					music = rs.getRecord(1);
					return music[0] == 1;
				}
			} catch

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -