本文概述
- 如何创建线?
- 物产
如何创建线? 请按照以下说明创建线。
- 实例化类javafx.scene.shape.Line。
- 设置类对象的必需属性。
- 将类对象添加到组中
属性 | 描述 | 设置方法 |
---|---|---|
endX | 线终点的X坐标 | setEndX(Double) |
endY | 线终点的y坐标 | setEndY(Double) |
startX | 直线起点的x坐标 | setStartX(Double) |
startY | 直线起点的y坐标 | setStartY(Double) |
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class LineDrawingExamples extends Application{ @Override public void start(Stage primaryStage) throws Exception {// TODO Auto-generated method stubLine line = new Line();
//instantiating Line class line.setStartX(0);
//setting starting X point of Lineline.setStartY(0);
//setting starting Y point of Line line.setEndX(100);
//setting ending X point of Line line.setEndY(200);
//setting ending Y point of Line Group root = new Group();
//Creating a Grouproot.getChildren().add(line);
//adding the class object //to the groupScene scene = new Scene(root, 300, 300);
primaryStage.setScene(scene);
primaryStage.setTitle("Line Example");
primaryStage.show();
} public static void main(String[] args) {launch(args);
}}
输出:
文章图片
示例2:创建多行
package application;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
public class LineDrawingExamples extends Application{ public static void main(String[] args) {launch(args);
} @Override public void start(Stage primaryStage) throws Exception {// TODO Auto-generated method stubprimaryStage.setTitle("Line Drawing Examples");
Line line1 = new Line(10, 50, 150, 50);
//Line(startX, startY, endX, endY) Line line2 = new Line(10, 100, 150, 100);
Line line3 = new Line(10, 50, 10, 100);
Line line4 = new Line(150, 50, 150, 100);
Group root = new Group();
root.getChildren().addAll(line1, line2, line3, line4);
Scene scene = new Scene (root, 300, 200, Color.GREEN);
primaryStage.setScene(scene);
primaryStage.show();
}}
【JavaFX Line】输出:
文章图片
推荐阅读
- JavaFX LineChart
- JavaFX灯光效果
- JavaFX Light.Spot效果
- JavaFX标签
- WinXP系统怎样恢复刚刚删除的文件?
- WinXP系统打开组策略的命令是啥?
- WinXP系统安装驱动提示没有通过Windows徽标测试如何处理?
- WinXP打开不了页面且提示处于脱机状态的处理办法
- WinXP系统如何运行Chkdsk命令?运行Chkdsk命令的办法