JavaMe连载(6)-自适应滚动显示 (二)

2014-11-24 07:56:20 · 作者: · 浏览: 3

graphics.translate(0, dir*currentPageIndex*bodyHeight);

for(int i=0; i {
graphics.drawString(info_wrap1[i],5, i * ft.getHeight()+head.menuHeight+margin, Graphics.TOP|Graphics.LEFT);
}

graphics.translate(0, -dir*currentPageIndex*bodyHeight);

drawScrollBar();
flushGraphics();

//System.out.println(graphics.getTranslateY());

}

private void drawScrollBar()
{
int barHeight = height-head.menuHeight-menu.menuHeight;

graphics.setColor(Color.menuFrame);
graphics.fillRect(width-3, head.menuHeight, 2, barHeight);
graphics.setColor(Color.selectBg);
graphics.fillRect(width-4, head.menuHeight+(currentPageIndex)*barHeight/page, 4, barHeight/page);
}

protected void keyPressed(int keyCode)
{
//System.out.println(keycode);
switch(keyCode)
{
case KeyID.SOFT_RIGHT:
{
String flag = "0";
Object [] args = {flag,""};
controller.handleEvent(UIController.EventID.EVENT_MAIN_SCREEN,args);
break;
}
default:
;
}

keyCode = getGameAction(keyCode);
//System.out.println(page);

switch(keyCode)
{

case UP:
{
dir = -1;


if(currentPageIndex>0)
{
currentPageIndex--;
}
else
{
//dir = 0;
}

show();
break;

}
case DOWN:
{
dir = -1;
if(currentPageIndex {
currentPageIndex++;
}
else
{
//dir = 0;
}

show();
break;
}
}
}

}
package com.token.view;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

import com.token.util.StringDealMethod;
import com.token.util.UIController;
import com.token.view.components.*;

public class ShowHelp extends GameCanvas
{
private UIController controller;
private Graphics graphics;
private Font ft;
private int width;
private int height;

private Menu menu;
private Head head;
private BackGroud backGroud;

private int page = 0;
private int currentPageIndex = 0;
private int bodyHeight;
private int dir = 0;

public ShowHelp(UIController control)
{
super(false);
this.controller=control;
setFullScreenMode(true);

width = getWidth();
height = getHeight();

menu = new Menu(this);
head = new Head(this);
backGroud = new BackGroud(this);
}

public void show()
{
int margin = 0;
graphics = getGraphics();

graphics.clipRect(0,0, width, height);
backGroud.drawBackGroud(this, graphics);
head.drawHead(this, graphics, "帮助