Skip to content

Instantly share code, notes, and snippets.

@joshyates1980
Created January 20, 2018 06:29
Show Gist options
  • Save joshyates1980/cb9a910fd8b78087731138eccd64b8d5 to your computer and use it in GitHub Desktop.
Save joshyates1980/cb9a910fd8b78087731138eccd64b8d5 to your computer and use it in GitHub Desktop.
Introduction to Java Programming, 11th Edition (Chapter 14 - FontDemo)
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.*;
import javafx.scene.control.*;
import javafx.stage.Stage;
public class FontDemo extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
// Create a pane to hold the circle
Pane pane = new StackPane();
// Create a circle and set its properties
Circle circle = new Circle();
circle.setRadius(50);
circle.setStroke(Color.BLACK);
circle.setFill(new Color(0.5, 0.5, 0.5, 0.1));
pane.getChildren().add(circle); // Add circle to the pane
// Create a label and set its properties
Label label = new Label("JavaFX");
label.setFont(Font.font("Times New Roman",
FontWeight.BOLD, FontPosture.ITALIC, 20));
pane.getChildren().add(label);
// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("FontDemo"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
@joshyates1980
Copy link
Author

Find another classmate and leave a comment on their gist code repository. It can be a generic message. My goal was to demo the gist functionality and how individuals can save their own code snippets and share with others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment