public void start(Stage primaryStage) { // Creates the pane and font objects to be used, as well as a string for the chars. Pane paneOne = new Pane(); Font mainFont = Font.font("Times New Roman", FontWeight.BOLD, FontPosture.REGULAR, 35); String text = "Welcome to Java "; // Makes a point in the very center of the 600x600 scene, a double for distance // from the center, and one for the starting rotation of the first character. double centerX = 300; double centerY = 300; double distance = 200; double rotation = 90; for (int i = 0; i < text.length(); i++) { /** * To make the positions work correctly, I treat the characters as elements on a unit circle. * I find the angle by multiplying 2 * pi by i, then dividing that by the length of the text. * Next, I find the A. cos and B. sin of the angle, and multiply that by the distance from the * center to find the change in X and Y respectively. Finally, the X and Y for the current * character are found by adding the change in X and Y to the center X and Y. */ double unitCircleAngle = (2 * Math.PI * i) / text.length(); double deltaX = distance * Math.cos(unitCircleAngle); double deltaY = distance * Math.sin(unitCircleAngle); double currentX = centerX + deltaX; double currentY = centerY + deltaY; // I make a string of the char at index i by finding the charAt, then using the // Character.toString // method to cast it a string; then I make a Text object using the current X and Y and the // current // character. I set the font, and current rotation of the character. Finally, I add 22.5 to // the rotation // to ensure that it is at the appropriate rotation for the next character. String tempChar = Character.toString(text.charAt(i)); ; Text tempText = new Text(currentX, currentY, tempChar); tempText.setFont(mainFont); tempText.setRotate(rotation); paneOne.getChildren().add(tempText); rotation = rotation + 22.5; } // I make a scene of the appropriate size using the pane with the characters, set the stage // title, add the // scene to the stage, and show it. Scene sceneOne = new Scene(paneOne, 600, 600); primaryStage.setTitle("Characters Around A Circle"); primaryStage.setScene(sceneOne); primaryStage.show(); }
public void start(Stage stage) { Button yesButton = new Button("Yes"); Button noButton = new Button("No"); Button maybeButton = new Button("Maybe"); final double rem = Font.getDefault().getSize(); HBox buttons = new HBox(0.8 * rem); buttons.getChildren().addAll(yesButton, noButton, maybeButton); VBox pane = new VBox(0.8 * rem); Label question = new Label("Will you attend?"); pane.setPadding(new Insets(0.8 * rem)); pane.getChildren().addAll(question, buttons); stage.setScene(new Scene(pane)); stage.show(); }