我编写了一个程序,其中在窗格中添加了一个浅蓝色矩形。然后将窗格添加到场景中。然后以场景中的矩形显示舞台。当我运行该程序时,情况正好相反。什么都没有出现。即使添加文字,也可以说没有文字。有人可以指出我做错了吗?我使用JavaFX作为GUI。这是我的代码:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class RectangleBound extends Application {
@Override
public void start(Stage primaryStage) {
Pane p = new Pane();
Rectangle rect = new Rectangle();
rect.setFill(Color.LIGHTSKYBLUE);
rect.setStroke(Color.DEEPSKYBLUE);
rect.setArcWidth(5);
// *C* set the width of the outline of rect to 5
p.getChildren().add(rect);
Scene sc = new Scene(p, 300, 300);
primaryStage.setScene(sc);
primaryStage.setTitle("Bound Rectangle");
primaryStage.show();
}
}
您尚未为Rectangle指定宽度和高度。请尝试以下方法,它应该可以工作。
Rectangle rect = new Rectangle(50, 50);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句