import java.util.concurrent.ThreadLocalRandom;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

 * Displays a label with a random floating-point number between 0 and 1, and a button for 
 * randomizing the number.
 * @version 1 (event handler is created as a named object of a named class)
 * @author Drue Coles
public class NumberServer extends Application {

    private final Label label = new Label();

    public void start(Stage primaryStage) {
        GridPane root = new GridPane();
        root.setPadding(new Insets(10));
        Scene scene = new Scene(root);

        // Add button and label to root pane.
        Button button = new Button("serve");
        root.add(button, 0, 0);
        root.add(label, 1, 0);

        // Style the button and label.
        String style = "-fx-font-size:24; -fx-font-weight: bold; -fx-text-fill: #1f2f4f";

        // Event handler is a named object of a named class. The code can be trivially 
        // modified to create the handler as an anonymous object of a named class. 
        class ButtonHandler implements EventHandler<ActionEvent> {

            public void handle(ActionEvent event) {
        ButtonHandler buttonHandler = new ButtonHandler();

        primaryStage.setTitle("Number Server");

     * Randomizes the label with a floating-point number between 0 and 1.
    private void randomizeLabel() {
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        String num = String.format("%1.8f", rand.nextDouble());

    public static void main(String[] args) {