如何使多边形显示

时间:2019-05-22 21:05:39

标签: java javafx

多边形不会在屏幕上绘制

窗口类是主类,而类位置是单独的类。问题不在于我已经确定的type.equals(“ NamedPlace”)。

   Public class Window {

   root.setCenter(Ggroup);

   class newHandlerMouse implements EventHandler<MouseEvent>{
    public void handle(MouseEvent event) {
        double x = event.getX();
        double y = event.getY();
        myAlert a = new myAlert();
        a.show();
        a.setHeaderText("Enter name of place");
        String name = a.getName();
        Position p = new Position(x, y);
        String catg = lView.getSelectionModel().getSelectedItem();
        RadioButton rB = (RadioButton)group.getSelectedToggle();
        String type = rB.getText();
        if (type.equalsIgnoreCase("NamedPlace")) {
            NamedPlace nPlace = new NamedPlace(p, catg, name);
            Ggroup.getChildren().add(nPlace);
        }
        root.removeEventHandler(MouseEvent.MOUSE_CLICKED, newClick);
        root.setCursor(Cursor.DEFAULT);
        New.setDisable(false);
    }
}

}

public class Place extends Polygon {

Position position;
String category, name;
Polygon polygon =  new Polygon();


public Place(Position p, String catg, String name) {

    this.name = name;
    this.position = p;
    this.category = catg;
    this.polygon.getPoints().addAll(new Double[]{ 
                        p.getX(), p.getY(),
                        p.getX()-20.0, p.getY()-40.0,
                        p.getX()+20.0, p.getY()-40.0 
    });
    if (catg.equalsIgnoreCase("Bus")) {
        this.polygon.setFill(Color.RED);
    } else if (catg.equalsIgnoreCase("Train")) {
        this.polygon.setFill(Color.GREEN);
    } else if (catg.equalsIgnoreCase("Underground")) {
        this.polygon.setFill(Color.BLUE);
    }

输出应该是单击时将多边形可见地添加到根中。

0 个答案:

没有答案