首页 > 解决方案 > setFill() & setStroke() 没有正确导入

问题描述

我正在启动 JavaFx,我想为我的圆圈分配一个填充和一个轮廓,我很快找到了 setFill () 和 setStroke () 函数,但我的 Eclipse 不理解它们,我不知道为什么!

我的代码:

package application;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Main extends Application {

    Circle cercle = new Circle(100,100,75);
    cercle.setFill(Color.YELLOW); 
    cercle.setStroke(Color.ORANGE);

    @Override
    public void start(Stage primaryStage) {
        try {
            BorderPane root = new BorderPane();
            Scene scene = new Scene(root,800,600, Color.YELLOW);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

标签: javajavafx

解决方案


  1. 您需要在您的开始(或其他)方法中调用setFill()andsetStroke()方法。
  2. 您需要将圆圈添加到BorderPane

公共类应用程序扩展应用程序
{

static Circle circle = new Circle(100, 100, 75); @Override public void start(Stage primaryStage) { try { BorderPane root = new BorderPane(); root.getChildren().add(circle); Scene scene = new Scene(root, 800, 600, Color.YELLOW); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.show(); } catch (Exception e) { e.printStackTrace(); } }


推荐阅读