1

下面的代码执行手绘,我的问题是这个类在 Linux 下编译,但在 WindowsXP 中出现错误。

在此处输入图像描述

这是代码

import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.ContextMenuEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathElement;


public class Freehand {
private Group               group ;
private FreeHandDrawPath    freehandDraw;

public Freehand(ObservableList<PathElement> _initFreehand) {

            this.freehandDraw = new FreeHandDrawPath(_initFreehand);        
    this.group = new Group();
    group.getChildren().add(freehandDraw);

            group.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
                @Override
                public void handle(final KeyEvent keyEvent) {

                    if (keyEvent.getCode() == KeyCode.DELETE ) {
                        group.getChildren().removeAll(freehandDraw);
                    }                        
                }
            });
}
class FreeHandDrawPath extends Path {            
        double x, y;
        final ContextMenu contextMenu = new ContextMenu();            
        final MenuItem itemDelete = new MenuItem("Delete");

        FreeHandDrawPath (ObservableList<PathElement> _initFreehand) {
                  super(_initFreehand);          

            setStroke(Color.BLACK);

            itemDelete.setOnAction(new EventHandler<ActionEvent>() {
            @Override
                public void handle(ActionEvent e) {
                    group.getChildren().removeAll(freehandDraw);
                    //System.out.println("Delete");
                }
            });

            contextMenu.getItems().addAll(itemDelete);

            this.addEventHandler(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {                            
                            // just to show that the line is selected
                            x = event.getX();
                            y = event.getY();
            setStroke(Color.RED);
                            setStrokeWidth(getStrokeWidth()+4);                                
                            group.requestFocus();
            event.consume();
        }
    });
            this.addEventHandler(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {                                
                            setStroke(Color.BLACK);
                            setStrokeWidth(getStrokeWidth()-4);
            event.consume();
        }
    });                

            this.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {                                                         
                    @Override
        public void handle(MouseEvent event) {                            

                        if (event.isSecondaryButtonDown()){                                                                
                            setOnContextMenuRequested(
                                    new EventHandler<ContextMenuEvent>() {
                                        @Override
                                        public void handle(ContextMenuEvent event) {
                                            //contextMenu.show(l, Side.RIGHT, 0, 0);
                                            contextMenu.show((Path) event.getSource(), event.getScreenX() + 1, event.getScreenY());
                                            //System.out.println("Hello World!");
                                        }
                            });
                        }
                        event.consume();
        }                      
    });                
        }
    }

    public Node view() {
    return group ;
}    
}

为什么我会收到这样的错误?

谢谢。

4

0 回答 0