import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class FreezeDemo extends Application {
	private int stockCount_ = 24;
	private Label status_;
	private Button draw_;

	@Override
	public void start ( Stage stage ) {
		status_ = new Label(stockCount_ + " cards in stock");
		draw_ = new Button("Draw");
		draw_.setOnAction(event -> onDraw(event));
		Button hint = new Button("Hint");
		hint.setOnAction(event -> onHint(event));

		VBox root = new VBox(10,status_,draw_,hint);
		stage.setScene(new Scene(root,300,180));
		stage.setTitle("Freeze Demo");
		stage.show();
	}

	private void onDraw ( ActionEvent event ) {
		stockCount_--;
		status_.setText(stockCount_ + " cards in stock");
		draw_.setDisable(stockCount_ == 0);
	}

	private void onHint ( ActionEvent event ) {
		status_.setText("Searching for a move...");
		findBestMove(); // blocks the UI thread
		status_.setText("Try the 7 of hearts");
	}

	private void findBestMove () {
		try {
			Thread.sleep(3000); // stands in for a slow search
		} catch ( InterruptedException e ) {
			Thread.currentThread().interrupt();
		}
	}

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