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 に答える