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

📄 getimage.java

📁 移动商务平台
💻 JAVA
字号:
/**
 *
 ******************************************
 ***  to Kristy,SUN YAT-SEN UNIVERSITY  *** 
 ******************************************  
 *
 *mTrade.java
 *Create on November,2003
 *Company:LeftBank
 *
 *@author Ben,XIDIAN UNIVERSITY
 *@version 0.1
 *
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;

import javax.microedition.io.*;
import java.io.*;


/**
 *this class downloads image from server 
 */  
public class GetImage 
{
     private String url;
     private String picName;
     RecordStore rs = null;
     mTrade mtrade;

     GetImage(mTrade mtrade,String url,String picName)
     {
          this.url = url;
          this.picName = picName;
          this.mtrade = mtrade;
          /**
           *creat a RecordStore if it doesn't exist,then add picName to it
           *data structure in rs:picName1->pic1->picName2->pic2.... 
           */           
          try
          {
               rs = RecordStore.openRecordStore(mtrade.rsName,true);
               byte[] b = picName.getBytes();
               rs.addRecord(b,0,b.length);
          }
          catch (Exception e)
          {
              System.out.println("Record Error!"); 
          }
     }

     public void download()
     {
          /**connect the server,download images and save it in RecordStore*/
          try
          {
               Alert alert = new Alert("info","downloading data,please wait..",null,AlertType.INFO);
               alert.setTimeout(Alert.FOREVER);
              mtrade.display.setCurrent(alert);



               DataInputStream ins = Connector.openDataInputStream(url);
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               int aByte;
               while((aByte = ins.read())!=-1)
               {
                    baos.write(aByte); 
               }
               byte[] b = baos.toByteArray();
               rs.addRecord(b,0,b.length);
               ins.close();
               baos.close();
          }
          catch(Exception e)
          {
               Alert alert = new Alert("Error","download Failled..",null,AlertType.ERROR);
               alert.setTimeout(Alert.FOREVER);
               mtrade.display.setCurrent(alert);
          }
     }
}

⌨️ 快捷键说明

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