|
| 1 | +import javafx.application.Application; |
| 2 | +import javafx.scene.Group; |
| 3 | +import javafx.scene.Scene; |
| 4 | +import javafx.scene.paint.Color; |
| 5 | +import javafx.scene.shape.Sphere; |
| 6 | +import javafx.scene.text.Font; |
| 7 | +import javafx.scene.text.Text; |
| 8 | +import javafx.stage.Stage; |
| 9 | + |
| 10 | +public class CelestialBodies extends Application { |
| 11 | + private static final int WIDTH = 800; |
| 12 | + private static final int HEIGHT = 600; |
| 13 | + |
| 14 | + private Group root; |
| 15 | + |
| 16 | + @Override |
| 17 | + public void start(Stage primaryStage) { |
| 18 | + root = new Group(); |
| 19 | + Scene scene = new Scene(root, WIDTH, HEIGHT, Color.BLACK); |
| 20 | + primaryStage.setScene(scene); |
| 21 | + primaryStage.setTitle("Celestial Bodies"); |
| 22 | + primaryStage.show(); |
| 23 | + |
| 24 | + createBodies(); |
| 25 | + } |
| 26 | + |
| 27 | + private void createBodies() { |
| 28 | + String[] bodyNames = {"Sun", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"}; |
| 29 | + double[] xCoordinates = {0, 50, 70, 100, 150, 220, 280, 350, 400}; |
| 30 | + double[] yCoordinates = {0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 31 | + double[] zCoordinates = {0, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 32 | + double[] sizes = {20, 5, 7, 7, 6, 18, 15, 12, 12}; |
| 33 | + |
| 34 | + for (int i = 0; i < bodyNames.length; i++) { |
| 35 | + double radius = sizes[i]; |
| 36 | + Sphere body = new Sphere(radius); |
| 37 | + body.setTranslateX(xCoordinates[i]); |
| 38 | + body.setTranslateY(yCoordinates[i]); |
| 39 | + body.setTranslateZ(zCoordinates[i]); |
| 40 | + body.setMaterial(new PhongMaterial(Color.WHITE)); |
| 41 | + root.getChildren().add(body); |
| 42 | + |
| 43 | + Text label = new Text(bodyNames[i]); |
| 44 | + label.setTranslateX(xCoordinates[i] - radius); |
| 45 | + label.setTranslateY(HEIGHT - 20); |
| 46 | + label.setFill(Color.WHITE); |
| 47 | + label.setFont(Font.font("Arial", 12)); |
| 48 | + root.getChildren().add(label); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public static void main(String[] args) { |
| 53 | + launch(args); |
| 54 | + } |
| 55 | +} |
0 commit comments