Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 移动互联网  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 如何设置Command的位置?
wenlive



发贴: 0
积分: 0
于 2004-02-18 20:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我想把某command设在左边,它却老跑到右边.除了command.exit一般被设在左.
下面是我的一个例了:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ListDemo extends MIDlet{
private Display display;
private int mode = List.IMPLICIT;
Command exitCommand,selectCommand,nextCommand;

public ListDemo(){
selectCommand = new Command( "Select ",Command.OK, 0);
exitCommand = new Command( "Exit ",Command.EXIT, 2 );

nextCommand = new Command( "Next ",Command.SCREEN, 2 );}

protected void destroyApp( boolean unconditional )
throws MIDletStateChangeException {
   exitMIDlet();
}

protected void pauseApp(){}

protected void startApp() throws MIDletStateChangeException {
if( display == null ){ // first time called...
initMIDlet();
}
}

private void initMIDlet(){
display = Display.getDisplay( this );
display.setCurrent( new SampleList( mode ) );
}

public void exitMIDlet(){
notifyDestroyed();
}

public static final String[] items = {
"First", "Second", "Third", "Fourth"
};

class SampleList extends List implements CommandListener {
private int mode;
SampleList( int mode ){
super( "", mode, items, null );
addCommand( selectCommand );
addCommand( exitCommand );

addCommand( nextCommand );
setCommandListener(this);

switch( mode ){
case IMPLICIT:
setTitle( "Implicit" );
break;
case EXCLUSIVE:
setTitle( "Exclusive" );
break;
case MULTIPLE:
setTitle( "Multiple" );
break;
}

this.mode = mode;
}

public void commandAction( Command c,Displayable d ){
if( c == exitCommand ){
exitMIDlet();
} else if( c == selectCommand ){
showSelection( false );
} else if( c == SELECT_COMMAND ){
showSelection( true );
} else if( c == nextCommand ){
if( mode == List.IMPLICIT ){
mode = List.EXCLUSIVE;
} else if( mode == List.EXCLUSIVE ){
mode = List.MULTIPLE;
} else {
mode = List.IMPLICIT;
}

display.setCurrent( new SampleList(mode));
}
}

private void showSelection( boolean implicit ){
Alert alert = new Alert(implicit?"Implicit Selection":"Explicit Selection" );
StringBuffer buf = new StringBuffer();

if( mode == MULTIPLE ){
boolean[] selected = new boolean[ size() ];
getSelectedFlags( selected );

for( int i = 0; i < selected.length; ++i ){
if( selected[i] ){
if( buf.length() == 0 ){
buf.append("You selected: " );
} else {
buf.append( ", " );
}

buf.append( getString( i ) );
}
}

if( buf.length() == 0 ){
buf.append( "No items are selected." );
}
} else {
buf.append("You selected ");
buf.append(getString(getSelectedIndex()));
}

alert.setString(buf.toString());
alert.setTimeout(Alert.FOREVER);

display.setCurrent(alert,display.getCurrent());
}
}
}
我想把"select"单独设在左边,它却老跑到右边去,只有"exit"能把它设在左边!




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923