小白教程

 找回密码
 立即注册
小白教程 首页 系列教程 Java系列教程 查看内容

JavaFX线

发布者: 小白教程



例子

以下代码创建一个Line对象,并使用setter方法设置开始和结束坐标。

import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.VBox;import javafx.scene.shape.Line;import javafx.stage.Stage; public class Main extends Application {     @Override    public void start(Stage stage) {        VBox box = new VBox();        final Scene scene = new Scene(box,300, 250);        scene.setFill(null);                Line line = new Line();        line.setStartX(0.0f);        line.setStartY(0.0f);        line.setEndX(100.0f);        line.setEndY(100.0f);                box.getChildren().add(line);                stage.setScene(scene);        stage.show();    }     public static void main(String[] args) {        launch(args);    }}

上面的代码生成以下结果。

null

例2

以下代码设置更多的线属性,包括笔触颜色,笔触宽度和线帽。

之后,它还设置了线的破折号样式。

import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.scene.paint.Color;import javafx.scene.shape.Line;import javafx.scene.shape.StrokeLineCap;import javafx.stage.Stage; public class Main extends Application {  @Override  public void start(Stage primaryStage) {    primaryStage.setTitle("Drawing Lines");     Group root = new Group();    Scene scene = new Scene(root, 300, 150, Color.GRAY);     Line redLine = new Line(10, 10, 200, 10);     redLine.setStroke(Color.RED);    redLine.setStrokeWidth(10);    redLine.setStrokeLineCap(StrokeLineCap.BUTT);     redLine.getStrokeDashArray().addAll(15d, 5d, 15d, 15d, 20d);    redLine.setStrokeDashOffset(10);     root.getChildren().add(redLine);     primaryStage.setScene(scene);    primaryStage.show();  }  public static void main(String[] args) {    launch(args);  }}

上面的代码生成以下结果。

null

12
上一篇:Java TCP服务器下一篇:Java流操作

Archiver|手机版|小黑屋|小白教程 ( 粤ICP备20019910号 )

GMT+8, 2024-9-20 06:28 , Processed in 0.017896 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】

返回顶部