0
我在JavaFX中構建了一個矩形。我的場景的寬度爲300,我的矩形寬度爲80.JavaFX矩形不會觸及右側
Rectangle.setX設置矩形左上角的位置。我將setX設置爲obScene.getWidth() - carRightSide,它不會碰到右側。
我在做什麼錯?
package assign3;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class Question4 extends Application
{
public int carRightSide;
@Override
public void start(Stage obPrimeStage) throws Exception
{
Pane obPane = new Pane();
Circle obWheelOne = new Circle(20, Color.BLACK);
obWheelOne.setRadius(20);
Circle obWheelTwo = new Circle(20, Color.BLACK);
obWheelTwo.setRadius(20);
Rectangle obBody = new Rectangle(80, 40, Color.LIGHTBLUE);
obPane.getChildren().add(obWheelOne);
obPane.getChildren().add(obBody);
Scene obScene = new Scene(obPane, 300, 350);
carRightSide = 80;
obBody.setX(obScene.getWidth() - carRightSide);
obBody.setY(40);
obPrimeStage.setTitle("Driving Cars");
obPrimeStage.setScene(obScene);
obPrimeStage.setResizable(false);
obPrimeStage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
}
完善後調整
Stage
的大小,謝謝! –