Overview

This JavaFX Hangman game picks a random word from a built-in word list, then lets the user guess letters. It displays the current word with underscores for unknown letters, tracks correct and incorrect guesses, and updates a graphical “hangman” drawing in a Label as wrong attempts increase.

Hangman Game Screenshot

Sample Code (HangManApp.java)

public class HangManApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Play the H A N G M A N game");
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.TOP_CENTER);
        grid.setPadding(new Insets(15));
        grid.setHgap(8);
        grid.setVgap(8);

        Scene scene = new Scene(grid, 500, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}