在我的 J2ME 应用程序中,我想在获得名为 as 的选择组控制的焦点时添加一个播放命令,Tones
并且在失去对选择组控制的关注后,应该删除该命令。
我该怎么做?
更新:
这是我的代码:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Focusoncontrol extends MIDlet implements CommandListener
{
Display disp;
TextField Text1, Text2, Text3;
ChoiceGroup Tones;
Form frm;
Command Save, Back, Play;
public Focusoncontrol()
{
disp = Display.getDisplay(this);
frm = new Form("Focus demo");
Text1 = new TextField("Text1", "", 20, 0);
Text2 = new TextField("Text2", "", 20, 0);
Text3 = new TextField("Text3", "", 20, 0);
Tones = new ChoiceGroup("Tones", Choice.POPUP, new String[]{"Tone 1", "Tone 2"}, null);
Save = new Command("Save", Command.SCREEN, 1);
Back = new Command("Back", Command.EXIT, 3);
Play = new Command("Play", Command.OK, 2);
frm.append(Text1);
frm.append(Text2);
frm.append(Tones);
frm.append(Text3);
frm.addCommand(Save);
frm.addCommand(Back);
frm.setCommandListener(this);
disp.setCurrent(frm);
}
public void startApp()
{
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable d)
{
if(c == Back)
{
destroyApp(true);
notifyDestroyed();
}
}
}
我没有在应用程序初始化期间添加播放命令,因为我必须在 Tones(ChoiceGroup 控件)获得焦点时在表单上添加播放命令,并在 ChoiceGroup 控件失去焦点时删除命令。