黑莓实地赛事没有被解雇?

时间:2012-09-13 12:08:43

标签: blackberry java-me

我在我的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);
}
}

1 个答案:

答案 0 :(得分:4)

试试这个:

 _startPlayingButton = new ButtonField("Play/pause")
{
    protected boolean navigationClick(int status, int time) 
    {
        fieldChangeNotify(1);
        return true;
    }
};