どのように処理中の関数のmousePressed()の引数としてオブジェクトを渡します

サミュエル・ジョン:

実行中のprintln(game.gameOn)静止画出力以下の機能のためにfalse

  1. なぜこの曖昧?
  2. 解決策は何ですか?

たぶん私は、関数のパラメータとしてオブジェクトを渡すことはできません mousePressed()

void mousePressed(Game game) {
    game.gameOn = false;
}
Rabbid76:

あなたはにオブジェクトを渡すことはできませんmousePressed()mousePressed()イベント処理中にシステムによって呼び出されるイベントコールバックとあります。

唯一の可能な引数は、mousePressed型のイベント引数ですMouseEvent.eg:

void mousePressed(MouseEvent event) {
   println("EVENT " + event);
}

あなたがオブジェクトにアクセスしたい場合mousePressed、あなたはグローバル変数を使用するようにしました。例えば:

Game game = new Game();

void mousePressed() {
   game.gameOn = false;
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=335144&siteId=1