使用JShell导入第三方类库OpenJFX(JavaFX)绘制简单图形

import javafx.application.Application
import javafx.stage.Stage
import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.scene.layout.AnchorPane
import javafx.scene.paint.Color
import javafx.scene.shape.Line
import java.io.File

class MainWindow extends Scene {
    public MainWindow() throws Exception {
        super(FXMLLoader.load(new File("D:\\CAH\\Creat\\2019\\Learn\\Applicarion\\JShell\\main.fxml").toURL()));
        AnchorPane anchorPane = (AnchorPane) lookup("#anchorPane");
        for(int i = 0; i < 11; i++){
            Line lineH = new Line();
            lineH.setStartX(50);
            lineH.setStartY(i * 50 + 50);
            lineH.setEndX(600 - 50);
            lineH.setEndY(i * 50 + 50);
            lineH.setStroke(Color.RED);
            lineH.setStrokeWidth(5);
            Line lineV = new Line();
            lineV.setStartX(i * 50 + 50);
            lineV.setStartY(50);
            lineV.setEndX(i * 50 + 50);
            lineV.setEndY(600 - 50);
            lineV.setStroke(Color.RED);
            lineV.setStrokeWidth(5);
            anchorPane.getChildren().add(lineH);
            anchorPane.getChildren().add(lineV);
        }
    }
}

class MainStage extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        // 50 per
        primaryStage.setMinWidth(600);
        primaryStage.setMinHeight(600);
        // 设置标题
        primaryStage.setTitle("画格子");
        // 加载显示面板到Stage容器内
        primaryStage.setScene(new MainWindow());
        // 设置窗口大小禁止改变
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}

Application.launch(MainStage.class)

上面这一段是JShell脚本

下面是main.fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            prefHeight="400.0" prefWidth="600.0" id="anchorPane">

</AnchorPane>

下面是运行结果:

使用命令 jshell --class-path * .\darwLine.java 导入OpenJFX并执行.\darwLine.java中的脚本。

--class-path后面是第三方jar包classpath的路径,*表示当前目录下全部jar包。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值