栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java、在一个多边形上吗?

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java、在一个多边形上吗?

 


package com.example.javafxproject;

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Polyline;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.util.linkedList;
import java.util.Scanner;

public class PolygonChart extends Application {
    private static linkedList list = new linkedList<>();

    public static void main(String[] args) {
        try(Scanner input = new Scanner(System.in);) {
            System.out.print("Enter five points: ");
            for (int i = 0; i < 10; i++)
                list.addLast(input.nextDouble());
        }
        launch(args);
    }
//    10 10 50 19 100 100 8 90 50 50

    @Override
    public void start(Stage primaryStage) {
        Scene scene = new Scene(getPane(), 500, 300);
        primaryStage.setScene(scene);
        primaryStage.setTitle("在一个多边形上吗?");
        primaryStage.show();
    }

    
    private Pane getPane() {
        BorderPane pane = new BorderPane();
        Polygon polygon = new Polygon();
        ObservableList observableList = polygon.getPoints();    //获取多边形的可观察列表并赋值引用

        while (list.size() > 2) //添加前4个点进入列表
            observableList.addAll(list.removeFirst(), list.removeFirst());

        Circle point = new Circle(list.removeFirst(), list.removeFirst(), 10);  //使用第5个点创建圆
        polygon.setStyle("-fx-fill: null; -fx-stroke: black;");

        pane.setCenter(new Group(polygon, point));
        pane.setBottom(new Text(10, 10, "The point is " + (polygon.contains(point.getCenterX(),
                point.getCenterY()) ? "" : "not ") + "inside the polygon"));
        BorderPane.setAlignment(pane.getBottom(), Pos.CENTER);
        BorderPane.setMargin(pane.getBottom(), new Insets(10));

        return pane;
    }
}

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/782574.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号