[英]How to draw a line in javaFX
我是 javaFX 的初學者,從今天開始我想所以我想如何畫線,當我創建一個新組並放置一個線對象時,它給了我一個錯誤,例如:
import java.awt.geom.Line2D;
import javafx.*;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class DrawingLine extends Application{
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage){
primaryStage.setTitle("Hello World!");
Button btn = new Button();
Line line = new Line(); //error
//Line2D line = new Line2D(); error
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
然后它說要導入 javax.sound.sampled 但它說我將其更改為 Line2D 而這不在 javafx 中並給我一個錯誤:“無法實例化 Line2D 類型”
為什么不能創建Line2D
?
像這樣使用Line
類:
Line line = new Line(100, 10, 10, 110);
您需要指定開始和結束坐標; 這條線從(100, 10)
到(10, 100)
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.