2

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

1 回答 1

4

试试这个:

 _startPlayingButton = new ButtonField("Play/pause")
{
    protected boolean navigationClick(int status, int time) 
    {
        fieldChangeNotify(1);
        return true;
    }
};
于 2012-09-14T06:20:56.773 回答