Пример #1
0
  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();
  }
Пример #2
0
  @Override
  public void start(Stage primaryStage) throws Exception {
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setVgap(10);
    grid.setHgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Scene sc = new Scene(grid, 500, 500);

    String css = Main.class.getResource("Login.css").toExternalForm();
    //        System.out.println(css);
    sc.getStylesheets().add(css);

    Text scenetitle = new Text("Welcome");
    //        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(scenetitle, 0, 0, 1, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField("Мудак");
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:"******"Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    btn.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            //                actiontarget.setFill(Color.FIREBRICK);
            actiontarget.setText("Pressed");
          }
        });

    //        grid.setGridLinesVisible(true);

    scenetitle.setId("welc");
    actiontarget.setId("act");

    primaryStage.setScene(sc);
    primaryStage.setTitle("Hello World");
    primaryStage.show();
  }