如何实现在不同screen的切换

来源:chinaitlab        2010-01-27 06:45:52        点击:
收藏本页:


顶一下

在midlet开发中,屏幕只有一个。如果需要显示不同的内容,可以在后台先准备好要显示的内容,然后通过Display.setcurrent(displayable d)函数来解决这个问题。但是如何

如何实现在不同screen的切换 由Linux系统中文网(Linux521.com)编辑收集整理,除Linux521注明原创文章外,其版权归原作者所有。如果您在学习中遇到问题欢迎在下面的评论中留言,我们会尽全力解答您的问题。

  在midlet开发中,屏幕只有一个。如果需要显示不同的内容,可以在后台先准备好要显示的内容,然后通过Display.setcurrent(displayable d)函数来解决这个问题。

  但是如何控制显示不同的内容呢?如果是程序里自动控制,那么就不存在这个问题;如果需要用户干预,进行屏幕的切换,又是如何实现的呢?

  其实思路也很简单,为每个屏幕设置相应的menu,然后这些menu的控制,统一由一个类来处理,那么就可以实现不同屏幕之间的切换了。

  package hello;

  import javax.microedition.midlet.*;

  import javax.microedition.lcdui.*;

  public class HelloMIDlet extends MIDlet implements CommandListener {

  private Command exitCommand; // The exit command

  private Command view;

  private Display display; // The display for this MIDlet

  private TextBox t;

  private MyCanvas m;

  public HelloMIDlet() {

  display = Display.getDisplay(this);

  exitCommand = new Command("Exit", Command.EXIT, 0);

  view = new Command("View", Command.ITEM, 1);

  }

  public void startApp() {

  t = new TextBox("Hello", "Hello, World!", 256, 0);

  t.addCommand(exitCommand);

  t.addCommand(view);

  t.setCommandListener(this);

  MyCanvas m=new MyCanvas();

  m.addCommand(exitCommand);

  m.addCommand(view);

  m.setCommandListener(this);

  if (System.getProperty(

  "microedition.io.file.FileConnection.version") != null)

  t.setTicker(new Ticker(System.getProperty(

  "microedition.io.file.FileConnection.version")));

  else

  t.setTicker(new Ticker("no"));

  display.setCurrent(m);

  }

  public void pauseApp() {

  }

  public void destroyApp(boolean unconditional) {

  }

  public void commandAction(Command c, Displayable s) {

  if (c == exitCommand) {

  destroyApp(false);

  notifyDestroyed();

  }

  if (c==view && s = m)

  {

  display.setCurrent(t);

  }

  }

  }

  以上代码中,主类实现了Commandlistener接口,所有屏幕的command都由这个类负责监听和处理。那么相当于由这个主类来决定如何切换屏幕.

  就这么简单。

内容来自www.linux521.com Linux系统中文网
《Linux系统中文网》欢迎原创作者投稿,请先注册成为会员,然后在后台 相应的栏目里提交你的文章,注意填写好相关信息点“保存”。我们将在24小时之内审核完毕。

我要评论: 如何实现在不同screen的切换
请务必尊重网上道德,遵守中华人民共和国的各项法律法规,承担一切因您的行为而直接或间接导致的法律责任。本站管理人员有权删除留言中的任意内容。

昵称  验证码  
热门
相关