まだグラフィカルユーザーインターフェイスをプログラミングすることができない場合は、JavaFX guisをプログラミングする方法を学ぶ必要があります。ここ
は、あなたの問題のために、単純なソリューションです:
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application
{
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
BorderPane borderPane = new BorderPane();
Button button = new Button("Click me");
button.setOnMousePressed(new ButtonPress());
borderPane.setCenter(button);
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
class ButtonPress implements EventHandler<MouseEvent>
{
@Override
public void handle(MouseEvent arg0)
{
System.out.println("Button is pressed");
}
}
}
これは進むべき道ではない...使用イベントの代わり –
あなたはボタンが押されたときに、あなたの 'MouseListener'変数を設定することができ、それらを観察します更新メソッドの変数 – Kayaman
いいえ、JavaはUIコンテキストそのものについて認識していません。これらはすべて基本的にOS固有のものです。まず、使用するUIフレームワークを決定し、そのUIフレームワークのコンテキストでこのイベントを確認する必要があります。 – hiergiltdiestfu