java左右滚动源码_Java编程源码,如何实现浏览器滚动代码呢?

滚动实例在们的

JavaMe坐标变更的功能怎么样实现。当有一定的相应的事件触发的时候,我们可以实现让其显示相关的页面,并且可以用滚动条滚动到相应的页面。

【JavaMe实现代码】

ShowHelp.java

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, "帮助");

menu.drawMenu(this, graphics, "","返回");

//flushGraphics();

ft = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM);

String info = "1 滚动分页显示;\n"

+"2 滚动分页显示;\n"

+"3 滚动分页显示;\n"

...

+"34 滚动分页显示;\n";

String info_wrap1[] = StringDealMethod.format(info, width-15, ft);

page = info_wrap1.length*ft.getHeight()/(height-head.menuHeight-menu.menuHeight-2*margin)+1;

bodyHeight = ((int) (height-head.menuHeight-menu.menuHeight)/ft.getHeight())*ft.getHeight();

margin = (height-head.menuHeight-menu.menuHeight-bodyHeight)/2;

graphics.setFont(ft);

graphics.setColor(Color.text);

graphics.clipRect(0, head.menuHeight+margin, width, bodyHeight);

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;

}

}

}

}

广州

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值