【发布时间】:2012-10-19 03:53:43
【问题描述】:
我在 Screen 构造函数中创建了一个按钮,但是当我单击该按钮时,我的事件没有执行,为什么会这样
我的代码是:
public myScreen(){
_startPlayingButton = new ButtonField("Play/pause");
_startPlayingButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
try {
// If the START button was pressed, begin playback
if (field == _startPlayingButton) {
// The player does not exist, we must initialize it
if (result) {
System.out.println("Result1" + result);
if (_player == null) {
// Create a stream using the remote file.
_source = new ShoutcastStream(_urlField.getText());
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
// Update the player status
// _playStatusField.setText("Started");
}
});
// Create and run the player's thread
_playerThread = new PlayerThread();
if (_playerThread != null) {
_playerThread.start();
} else {
System.out.println("PlayerThread is null.");
}
}
// The player already exists, simply resume it
else {
_player.start();
}
result = false;
} else {
// Acquire the UI lock
System.out.println("Result2" + result);
UiApplication.getUiApplication().invokeLater(new
Runnable() { public void run() {
("Stopped"); } });
}
});
// Destroy the Player and streams
destroy();
result = true;
}
}
// If the STOP button was pressed:
} catch (IOException ioe) {
ioe.printStackTrace();
errorDialog(ioe.toString());
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e);
}
}
});
add(_startPlayingButton);
}
}
【问题讨论】:
-
你怎么知道它没有被解雇?
-
我调试它,它没有打印我的系统输出?
-
可以检查您是否没有为此按钮设置另一个更改侦听器
-
您的问题格式错误,包含大量错误。
startPlayingButton.setChangeListener(new FieldChangeListener() { public void fieldChanged(Field field, int context) { System.out.println("Event fired."); } });- 检查此代码是否适用于您的模拟器。您必须更新您的问题,并删除不必要的代码。如果您使用的是 Eclipse IDE,请按Ctrl-A和Ctrl-Shift-F格式化您的代码。 -
播放器实例初始化、流媒体文件、推新屏显示栈相关的代码实际上与你提到的问题无关。所以你可以删除那些。
标签: blackberry java-me