日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

J2ME中實(shí)現(xiàn)可伸展目錄樹TreeList_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:jsp中javaBean的運(yùn)用
Jsp的一個(gè)重要特性就是可以用javaBean實(shí)現(xiàn)功能的擴(kuò)展。將大部分功能放在javaBean中完成,以使jsp頁面程序更干凈簡潔、利于維護(hù)。JavaBean可以很方便的用來捕獲頁面表單的輸入并

  J2ME里面有自帶的List類,但是功能太弱,沒有實(shí)現(xiàn)View和Model的分離,所以操作起來比較費(fèi)事。本來事想寫一個(gè)Canvas的TreeList,但是畫起來算坐標(biāo)又太麻煩,所以選取了一個(gè)折中的方法,繼承List,實(shí)現(xiàn)一個(gè)操作起來比較方便的組件。

  目的:

  1.可伸縮的目錄樹結(jié)構(gòu),暫時(shí)先實(shí)現(xiàn)兩層。

  2.Label和存儲內(nèi)容分離。

  3.激活和非激活圖片分開。

  4.通過選擇事件可以準(zhǔn)確快速找到對應(yīng)內(nèi)容

  5.存儲內(nèi)容無關(guān)性,里面可以放置任何Object

  實(shí)現(xiàn)思路:

  1.封裝一個(gè)ExpandItem類,用來存儲每一條數(shù)據(jù)。

/**
* 默認(rèn)圖片
*/
private String imagePath="";
/*
* 激活圖片,如果為空說明此圖片無效
*/
private String selectImgPath=null;
/**
* 組
*/
public static int GROUP=1;
/**
* 記錄
*/
public static int ITEM=0;
/**
* 是否選中,如果選中則默認(rèn)為展開狀態(tài)
*/
private boolean ifselected=false;
/**
* 顯示Label
*/
private String label;
/**
* 類型:組,記錄
*/
private int type;
/**
* 存儲的對象
*/
  GROUP表示這個(gè)ITEM是一個(gè)父節(jié)點(diǎn),下面包含字節(jié)點(diǎn),這樣它的Content將是一個(gè)Vector.ITEM表示這個(gè)ITEM是根節(jié)點(diǎn)。

  selectImgPath,是激活后的圖標(biāo),可以為空,為空的時(shí)候選擇了這個(gè)ITEM圖標(biāo)不變。

  然后就是ExpandList類,此類的數(shù)據(jù)結(jié)構(gòu)如下:

private Vector itemList = new Vector();

/*用來存儲內(nèi)容的數(shù)據(jù)結(jié)構(gòu)*/

private ExpandListItem currentSelectedObject = null;

/*當(dāng)前所選擇的對象,方便獲取*/

private int currentSelectedIndex = -1;

/*當(dāng)前選擇的對象在隊(duì)列中的Index,隊(duì)列有兩個(gè),一個(gè)是真實(shí)數(shù)據(jù)的存儲Vector,另外一個(gè)是顯示在屏幕上的隊(duì)列。這兩個(gè)有時(shí)候是不一樣的。因?yàn)橛械墓?jié)點(diǎn)有子節(jié)點(diǎn)*/

private Vector appearHookList = new Vector();

/*顯示在屏幕上的Label隊(duì)列*/
  總的思路如下:

  初始化List的時(shí)候,參數(shù)是一個(gè)Vector,里面可以是ExpandItem或者是Vector.然后根據(jù)ExpandItem里面的參數(shù)初始化屏幕,如果GROUP節(jié)點(diǎn)的ifselected狀態(tài)為True則遞歸添加下面的子節(jié)點(diǎn),否則只插入當(dāng)前節(jié)點(diǎn)。圖標(biāo)也是一樣,如果ifselected為True 則用激活圖標(biāo)否則用默認(rèn)圖標(biāo)。

  在用戶選擇了一個(gè)結(jié)點(diǎn)后,取得當(dāng)前的激活的Index號碼,判斷是不是父節(jié)點(diǎn),如果是的話,首先更新這個(gè)父節(jié)點(diǎn)的Ifselected屬性為True,然后重畫這個(gè)List;(其實(shí)效率更高的方法是直接插入這個(gè)父節(jié)點(diǎn)的子節(jié)點(diǎn),但是這樣做的話,在移除的時(shí)候會稍微稍微麻煩一點(diǎn)。有時(shí)間我在改過來,呵呵)。如果選擇的是子節(jié)點(diǎn),則判斷是否有激活圖標(biāo),如果有,則更新這個(gè)圖標(biāo),就好了。

  下面是效果

點(diǎn)此在新窗口瀏覽圖片 點(diǎn)此在新窗口瀏覽圖片 點(diǎn)此在新窗口瀏覽圖片
 附代碼一份,這是我ME組件庫中很早的版本了。別的組件以后在寫。其實(shí)最好的方法就是寫Canvas。

ExpandList.java

package com.skystudio.ExpandList;

public class ExpandListItem {
  public ExpandListItem(Object content,String imgPath,String selectImgPath,String Label,int type,boolean ifselected){
   this.selectImgPath=selectImgPath;
   this.imagePath=imgPath;
   this.content=content;
   this.label=Label;
   this.type=type;
   this.ifselected=ifselected;
  }
  /**
  * 默認(rèn)圖片
  */
  private String imagePath="";
  /*
  * 激活圖片,如果為空說明此圖片無效
  */
  private String selectImgPath=null;
  /**
  * 組
  */
  public static int GROUP=1;
  /**
  * 記錄
  */
  public static int ITEM=0;
  /**
  * 是否選中
  */
  private boolean ifselected=false;
  /**
  * 顯示Label
  */
  private String label;
  /**
  * 類型:組,記錄
  */
  private int type;
  /**
  * 存儲的對象
  */
  private Object content;
   public Object getContent() {
    return content;
   }
  public void setContent(Object content) {
   this.content = content;
  }
  public String getLabel() {
   return label;
  }
  public void setLabel(String label) {
   this.label = label;
  }
  public int getType() {
   return type;
  }
  public void setType(int type) {
   this.type = type;
  }
  public boolean Ifselected() {
   return ifselected;
  }
  public void setIfselected(boolean ifselected) {
   this.ifselected = ifselected;
  }
  public String toString() {
   return this.label " ";
  }
  public String getImagePath() {
   return imagePath;
  }
  public void setImagePath(String imagePath) {
   this.imagePath = imagePath;
  }
  public String getSelectImgPath() {
   return selectImgPath;
  }
  public void setSelectImgPath(String selectImgPath) {
   this.selectImgPath = selectImgPath;
  }
}

--------------------------------------------------------------------------------

package com.skystudio.ExpandList;

import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

import com.skystudio.ui.toolkit.Util;

/**
* @author sky
*
*/
public class ExpandList extends List implements CommandListener {
  private Vector itemList = new Vector();

  private ExpandListItem currentSelectedObject = null;

  private int currentSelectedIndex = -1;

  private Vector appearHookList = new Vector();

  public ExpandList(String title, int type, Vector itemList) {
   super(title, type);
   this.itemList = itemList;
   this.setCommandListener(this);
   LoadList();
  }

  public void appendItem(ExpandListItem item, Image icon, boolean ifSub) {
   appearHookList.addElement(item);
   System.out.println("Add current display list:" item);
   if (!ifSub) {
    this.append(item.getLabel(), icon);
   } else {
    this.append(" " item.getLabel(), icon);
   }
  }

  public void Init() {
   int count = this.size();
   for (int i = 0; i < count; i ) {
    this.delete(0);
   }
   this.appearHookList.removeAllElements();
    System.out.println("Now itemList:" this.itemList);
  }

  public void LoadList() {
   Init();
   for (int i = 0; i < itemList.size(); i ) {
    ExpandListItem elItem = (ExpandListItem) itemList.elementAt(i);
    if (elItem.getType() == ExpandListItem.GROUP) {
     Image icon = Util.getImage(elItem.getImagePath());
    /**
     * @Debug
    */
    if (elItem.Ifselected()) {
     if (elItem.getSelectImgPath() != null) {
      icon = Util.getImage(elItem.getSelectImgPath());
     }
     System.out.println("Add Parent Node:");
     this.appendItem(elItem, icon, false);
     Vector group = (Vector) elItem.getContent();
     for (int j = 0; j < group.size(); j ) {
      ExpandListItem item = (ExpandListItem) group.elementAt(j);
      Image ic = Util.getImage(item.getImagePath());
      System.out.println("Add Sub Node:");
      this.appendItem(item, ic, true);
     }
     } else {
      System.out.println("Add Leave Node:");
      this.appendItem(elItem, icon, false);
     }
    } else if (elItem.getType() == ExpandListItem.ITEM) {
     Image icon = Util.getImage(elItem.getImagePath());
     this.appendItem(elItem, icon, false);
    }
   }
   if (this.currentSelectedIndex != -1) {
    this.setSelectedIndex(currentSelectedIndex, true);
   }
  }

  public Vector getItemList() {
   return itemList;
  }

  public void setItemList(Vector itemList) {
   this.itemList = itemList;
  }

  public void commandAction(Command arg0, Displayable arg1) {
   if (arg0 == List.SELECT_COMMAND) {
    /**
     * Set Current List Selected status
    */
    this.currentSelectedIndex = this.getSelectedIndex();
    System.out.println(this.appearHookList);

    this.currentSelectedObject = (ExpandListItem) this.appearHookList.elementAt(currentSelectedIndex);

    int indexInItemList = this.itemList.indexOf(this.appearHookList.elementAt(this.getSelectedIndex()));
    System.out.println(" Selected: " currentSelectedIndex " " this.currentSelectedObject " indexInItemList:" indexInItemList);
    /**
    *
    */
    if (this.currentSelectedObject.getType() == ExpandListItem.GROUP) {
     if (this.currentSelectedObject.Ifselected() == false) {// Previous
      // item
      // status
      // is
      // contractive,need
      // to be
      // expanded.
      System.out.println(this.currentSelectedObject.Ifselected());
      this.itemList.removeElementAt(indexInItemList);
      this.currentSelectedObject.setIfselected(true);
      this.itemList.insertElementAt(currentSelectedObject,
      indexInItemList);
     } else {
      this.itemList.removeElementAt(indexInItemList);
      this.currentSelectedObject.setIfselected(false);
      this.itemList.insertElementAt(currentSelectedObject,
      indexInItemList);
     }
     this.Init();
     this.LoadList();
    } else {
     if (this.currentSelectedObject.getSelectImgPath() != null) {
      if (this.currentSelectedObject.Ifselected() == false) {
       Image icon = Util.getImage(this.currentSelectedObject.getSelectImgPath());
       System.out.println(this.currentSelectedObject.Ifselected());
       this.itemList.removeElementAt(indexInItemList);
       this.currentSelectedObject.setIfselected(true);
       this.itemList.insertElementAt(currentSelectedObject,indexInItemList);
       this.delete(this.currentSelectedIndex);
       this.insert(this.currentSelectedIndex,
       this.currentSelectedObject.getLabel(), icon);
      } else {
       Image icon = Util.getImage(this.currentSelectedObject.getImagePath());
       this.itemList.removeElementAt(indexInItemList);
       this.currentSelectedObject.setIfselected(false);
       this.itemList.insertElementAt(currentSelectedObject,indexInItemList);
       this.delete(this.currentSelectedIndex);
       this.insert(this.currentSelectedIndex,
       this.currentSelectedObject.getLabel(), icon);
      }
      this.setSelectedIndex(this.currentSelectedIndex,true);
     }
    }
   }
  }
}
  附測試代碼

import java.util.Vector;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.skystudio.Canvas.ListCanvas;
import com.skystudio.ExpandList.ExpandList;
import com.skystudio.ExpandList.ExpandListItem;

public class Main extends MIDlet {
  Display d=null;
  protected void startApp() throws MIDletStateChangeException {
   d=Display.getDisplay(this);
   ListTest();
  }
  private void TestUI(){
   ListCanvas l=new ListCanvas();
   d.setCurrent(l);
  }
  private void ListTest(){
   Vector v1=new Vector();
   for(int i=0;i<10;i ){
    v1.addElement(new ExpandListItem("土匪" Integer.toString(i),"/img/default.png","/img/Group-open.png","土匪" Integer.toString(i),ExpandListItem.ITEM,false));
   }
   String v2="警察";
   Vector v3=new Vector();
   for(int i=0;i<10;i ){
    v3.addElement(new ExpandListItem("警察" Integer.toString(i),"/img/default.png","/img/Group-open.png","警察" Integer.toString(i),ExpandListItem.ITEM,false));
   }
   Vector v=new Vector();
   v.addElement(new ExpandListItem(v1,"/img/Group-close.png","/img/Group-open.png","土匪幫",ExpandListItem.GROUP,false));
   v.addElement(new ExpandListItem(v3,"/img/Group-close.png","/img/Group-open.png","警察局",ExpandListItem.GROUP,false));
   v.addElement(new ExpandListItem(v2,"/img/default.png","/img/Group-open.png","法官",ExpandListItem.ITEM,false));
   d.setCurrent(new ExpandList("花名冊",Choice.IMPLICIT,v));
  }

  protected void pauseApp() {
   // TODO Auto-generated method stub
  }

  protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
   // TODO Auto-generated method stub
  }
}

分享:從jsp發(fā)送動(dòng)態(tài)圖像
你是否曾經(jīng)想過從jsp頁面(或者servlet)中發(fā)送動(dòng)態(tài)產(chǎn)生的圖像?這篇技巧告訴你如何做。要運(yùn)行這里的代碼,你需要一個(gè)Tomcat或者其他支持JSP 1.1的web服務(wù)器。 當(dāng)一個(gè)web頁面帶有

來源:模板無憂//所屬分類:JSP教程/更新時(shí)間:2008-08-22
相關(guān)JSP教程