j2meblog

symbian

自己总结的一些J2ME开发经验点滴

想实现一个UI,提示用户输入PIN码,输入完后函数返回用户输入的PIN码。代码如下:

public class PinInputForm
 extends Form
 implements CommandListener
{

......

 public String GetInputPIN(Display display)
 {
  //show dialog
  Displayable prevUi= display.getCurrent();
  display.setCurrent(this);
  //wait for "ok"
  synchronized(this){
   try{
    wait();
   }catch(Exception e){}
  }
  display.setCurrent(prevUi);
  return m_strRet;
 }
 public void commandAction(Command c, Displayable s)
 {
  if(c==m_CancelCommand)
  {
   m_strRet=null;
   synchronized(this){
    notify();
   }
  }
  else if(c==m_OkCommand)
  {
   m_strRet= m_txtBoxPIN.getString();
   synchronized(this){
    notify();
   }
  }
 }
}

这在Windows下很好实现,只要一个模式对话框就可以。但发现在J2ME环境下,竟然无法实现。原因是:J2ME为Midlet提供一个UI线程,且仅有一个。如果用户在该线程下阻塞,Midlet就得不到再次调度

系统原理如下:

 

经过调用Connet后:

 

如果在connet处阻塞的话,系统线程就出不来了

来源:http://www.j2mehome.com/ j2me教程 CLDC

 

posted on 2009-07-16 19:51 j2meer 阅读(145) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。