package moder.view; import java.io.IOException; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.game.Sprite; public class NineList { private int W,H, icow,//图标宽 strh;//字符高 private int empty;//间隔距离 private Image img_pp; private int[] px,py; private final int listcount;//列表总数 public final static String[] menutag={"最近阅读", "分类列表","图书搜索","我的收藏","火爆排行", "最新上架","软件设置"}; public NineList(int w,int h,int listnum){ W=w; H=h; listcount=listnum; try { if(W>208||H>208){ img_pp=Image.createImage("/list_large.png"); strh=15; empty=10; } else{ img_pp=Image.createImage("/list_small.png"); strh=11; empty=6; } icow=img_pp.getWidth()/listcount;//每个图片的尺寸 } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } px=new int[]{W/2-icow*3/2-empty,W/2-icow/2,W/2+icow/2+empty}; py=new int[]{empty,icow+2*empty+empty,2*icow+3*empty+2*empty}; } public void drawMenu(Graphics g,int row){ row=row%listcount;//过滤过大数 if(row<0){ row+=listcount; } selectedRect(g,px[row%3],py[row/3]); //画固定列表 g.drawRegion(img_pp, icow*0, 0, icow, icow+strh, Sprite.TRANS_NONE, px[0],py[0], 20); g.drawRegion(img_pp, icow*1, 0, icow, icow+strh, Sprite.TRANS_NONE, px[1],py[0], 20); g.drawRegion(img_pp, icow*2, 0, icow, icow+strh, Sprite.TRANS_NONE, px[2],py[0], 20); g.drawRegion(img_pp, icow*3, 0, icow, icow+strh, Sprite.TRANS_NONE, px[0],py[1], 20); g.drawRegion(img_pp, icow*4, 0, icow, icow+strh, Sprite.TRANS_NONE, px[1],py[1], 20); g.drawRegion(img_pp, icow*5, 0, icow, icow+strh, Sprite.TRANS_NONE, px[2],py[1], 20); g.drawRegion(img_pp, icow*6, 0, icow, icow+strh, Sprite.TRANS_NONE, px[0],py[2], 20); } /** * 画选择框 * @param g * @param x * @param y */ private void selectedRect(Graphics g,int x,int y){ g.setColor(0xff0000); g.drawRoundRect(x-2, y-2, icow+3, icow+3, 15, 15); } }