java - 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);
}
}
解决方案
- 您需要在您的开始(或其他)方法中调用
setFill()
andsetStroke()
方法。 - 您需要将圆圈添加到
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();
}
}
推荐阅读
- c++ - 将基类转换为派生类时 dynamic_cast 失败
- python - 如何基于现有列创建新的 pandas 列?
- computer-vision - 如何在树莓派 4 中安装 pypylon
- excel - 自动生成 FDF 文件
- python - C:/Python27/ArcGIS10 不存在
- odata - Azure 数据工厂 SAP ECC OData 连接参数
- javascript - 反应功能没有从功能组件传递到功能组件
- solr - solr 在主要搜索结果中集成突出显示数据
- c# - C# SOAP 服务:在 SOAP 标头中签名“wsu:Timestamp 和 wsa:To”元素
- javascript - 如何在代码隐藏(C#)中提交表单?