Ejemplo n.º 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();
  }
Ejemplo n.º 2
0
  public FamilyForm() {

    getStylesheets().add("/CSS/familyFormCss.css");

    save = new Button("Save");
    cancel = new Button("Cancel");

    Title.setFontSmoothingType(FontSmoothingType.LCD);
    Title.setFont(javafx.scene.text.Font.font(20));

    scrollPane = new ScrollPane(getSubGrid());
    scrollPane.setFitToWidth(true);

    save.setPrefWidth(80);
    cancel.setPrefWidth(80);

    clientID = Controller.getInstance().getStaffInfo().getAccountID();

    /////////////////////////////////// MAIN PANE ///////////////////////////////////

    setConstraints(Title, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER);
    setConstraints(scrollPane, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER);

    getChildren().addAll(Title, scrollPane);

    save.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            if (Validate()) {
              String name = Name.getText().trim();

              if (Controller.isNotified && orginalName.equals("")) {
                orginalName = name;
              } else if (Controller.isNotified && !(orginalName.equals(""))) {
                if (!orginalName.equals(name)) {
                  orginalName = name;
                  Controller.isNotified = false;
                }
              }
              Save();
            }
          }
        });

    cancel.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            clear();
          }
        });
  }