【发布时间】:2017-07-09 18:40:49
【问题描述】:
我正在运行的程序,显然不是。有人可以帮我吗?我是 JavaFX 的初学者。
Analog_clock.java
package analog_clock;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
/**
*
* @author ishansrivastava
*/
public class Analog_clock extends Application {
@Override
public void start(Stage primaryStage) {
Circle circle = new Circle();
circle.setCenterX(100.0f);
circle.setCenterY(100.0f);
circle.setRadius(50.0f);
Group g = new Group();
g.getChildren().add(circle);
Pane bg = new Pane();
//bg.setBackground(new Background(new BackgroundFill("-fx-color: #ACACE6", null,null)));
bg.getChildren().add(g);
Scene scene = new Scene(bg, 300, 250);
scene.getStylesheets().add(this.getClass().getResource("style.css").toExternalForm());
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show()cl;
}
public static void main(String[] args) {
launch(args);
}
}
style.css
.Circle
{
-fx-stroke: #757575; /* sonic silver */
-fx-fill: #00CC99; /* caribbean green */
}
.pane
{
-fx-background-color: #ACACE6; /* maximum blue purple */
}
谢谢你帮助我。
更新:
将我的 css 文件更改为此后:
.circle
{
-fx-stroke: #757575; /* sonic silver */
-fx-fill: #00CC99; /* caribbean green */
}
.root
{
-fx-background-color: #ACACE6; /* maximum blue purple */
}
我的背景看起来是紫色的,因为我的代码中没有 没有名为 root 的东西。
【问题讨论】:
-
欧文有什么问题?我没明白。
-
为什么颜色没有像我在我的 css 文件中定义的那样出现?