Source of FontDemo.java


  1: 
  2: import javafx.application.Application;
  3: import javafx.scene.Scene;
  4: import javafx.scene.layout.*;
  5: import javafx.scene.paint.Color;
  6: import javafx.scene.shape.Circle;
  7: import javafx.scene.text.*;
  8: import javafx.scene.control.*;
  9: import javafx.stage.Stage;
 10: 
 11: public class FontDemo extends Application {
 12:   @Override // Override the start method in the Application class
 13:   public void start(Stage primaryStage) {
 14:     // Create a pane to hold the circle
 15:     Pane pane = new StackPane();
 16: 
 17:     // Create a circle and set its properties
 18:     Circle circle = new Circle();
 19:     circle.setRadius(50);
 20:     circle.setStroke(Color.BLACK);
 21:     circle.setFill(new Color(0.5, 0.5, 0.5, 0.1));
 22:     pane.getChildren().add(circle); // Add circle to the pane
 23: 
 24:     // Create a label and set its properties
 25:     Label label = new Label("JavaFX");
 26:     label.setFont(Font.font("Times New Roman",
 27:       FontWeight.BOLD, FontPosture.ITALIC, 20));
 28:     pane.getChildren().add(label);
 29: 
 30:     // Create a scene and place it in the stage
 31:     Scene scene = new Scene(pane);
 32:     primaryStage.setTitle("FontDemo"); // Set the stage title
 33:     primaryStage.setScene(scene); // Place the scene in the stage
 34:     primaryStage.show(); // Display the stage
 35:   }
 36: 
 37:   /**
 38:    * The main method is only needed for the IDE with limited
 39:    * JavaFX support. Not needed for running from the command line.
 40:    */
 41:   public static void main(String[] args) {
 42:     launch(args);
 43:   }
 44: }