javaMe翻页
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 22:49 点击:次
public class Test extends MIDlet{
private Display display;
private TextCanvas tcanvas;
public Test() {
// TODO Auto-generated constructor stub
display=Display.getDisplay(this);
tcanvas=new TextCanvas(this);
}
protected void startApp() throws MIDletStateChangeException {
display.setCurrent(tcanvas);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
//翻页实现类
public class TextCanvas extends Canvas {
InputStream is;
InputStreamReader ir;
int b=0,page=1,num=-1;
private int count=0;
private String str=new String();
private String ss=new String();
private static final int MAX_SIZE=10;
public TextCanvas(Test test) {
str=this.getText();
System.out.println("--text.size--"+str.length());
}
protected void paint(Graphics g) {
// TODO Auto-generated method stub
int x = 0;
int y = 0;
//设置画布颜色
// g.setColor(0xD8d8BF);
// g.fillRect(0,0,this.getWidth(),this.getHeight());
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), this.getHeight());
ss=this.TurnPage(count);
g.setColor(0x000000);//设置内容颜色
g.drawString(ss, x, y,Graphics.LEFT|Graphics.TOP);
}
protected void keyPressed(int keyCode){
//4向前翻页,6向后翻页;
if(keyCode==Canvas.KEY_NUM6){
System.out.println("-------6向后翻页--------");
this.changePage(page);
page++;
this.repaint();
}
else if(keyCode==Canvas.KEY_NUM4){
System.out.println("---------4向前翻页----------");
this.changePage(page-1);
page--;
this.repaint();
}
}
//翻页功能pageNum==1时向下翻一页,pageNum==-1时向上翻一页
public int changeP
相关新闻>>
- 发表评论
-
- 最新评论 更多>>