Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX将鼠标事件处理程序分配给Arc_Java_Javafx_Automatic Ref Counting_Mouse - Fatal编程技术网

JavaFX将鼠标事件处理程序分配给Arc

JavaFX将鼠标事件处理程序分配给Arc,java,javafx,automatic-ref-counting,mouse,Java,Javafx,Automatic Ref Counting,Mouse,我有一个Arc,并且喜欢在控制器类中分配事件处理程序。 我在Swing JPanel中构建了一个JFXPanel。 面板I初始化如下: public void init() { Platform.runLater( new Runnable() { @Override public void run() { try { FXMLLoader loader = new FXMLLoader( getCla

我有一个Arc,并且喜欢在控制器类中分配事件处理程序。 我在Swing JPanel中构建了一个JFXPanel。 面板I初始化如下:

    public void init()
    {
       Platform.runLater( new Runnable() {
       @Override
       public void run()   {
       try {
         FXMLLoader loader = new FXMLLoader( getClass().getResource("fxml.fxml" ));
         Pane myPane = (Pane) loader.load();
         controller = loader.getController();
         Scene scene = new Scene( myPane );
         setScene( scene );
      }
      catch ( Exception e ) {
         e.printStackTrace();
      }  
    }
  }); 
 }
在控制器类中: 我在FXML文件中声明了同名的arc

    @FXMLprivate Arc   arc;
在初始化方法中,我执行了以下操作:

    @FXML
    protected void initialize()
    {
        arc.setOnMouseClicked( new EventHandler<Event>() {

        @Override
        public void handle( Event event )
        {
            System.out.println("Evento");
        }
    } );
但是,事件未被激发。

此问题类似于:。该代码也类似,适用于链接的QuadCurve情况。在您的代码中有@FXMLprivate,在@FXML和private之间没有空格,您需要在这两个单词之间有空格,否则FXML加载程序无法初始化arc成员。