// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package demo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class OldStyleJavaFXGUI extends Application {
    private Calculator data = new Calculator();
    private TextField number;
    private Label sqrt;
    private Label log;
    private Label exp;
    @Override
    public void start(Stage stg) throws Exception {
        stg.setTitle("Old style JavaFX GUI");
        GridPane pn = new GridPane();
        pn.setStyle("-fx-background-color: yellow;");
        number = new TextField();
        pn.add(new Label("Number"), 0, 0);
        pn.add(number, 1, 0);
        pn.add(new Label("Square root"), 0, 1);
        sqrt = new Label();
        sqrt.setStyle("-fx-text-fill: blue;");
        pn.add(sqrt, 1, 1);
        pn.add(new Label("Logarithm"), 0, 2);
        log = new Label();
        log.setStyle("-fx-text-fill: blue;\"");
        pn.add(log, 1, 2);
        pn.add(new Label("Exponential"), 0, 3);
        exp = new Label("");
        exp.setStyle("-fx-text-fill: blue;\"");
        pn.add(exp, 1, 3);
        Button calc = new Button("Calculate");
        calc.setStyle("-fx-background-color: red;");
        calc.setOnAction((e) -> {
            double x = Double.parseDouble(number.getText());
            data.setNumber(x);
            sqrt.setText(Double.toString(data.getSqrt()));
            log.setText(Double.toString(data.getLog()));
            exp.setText(Double.toString(data.getExp()));
        });
        pn.add(calc, 0, 4);
        Scene scn = new Scene(pn);
        stg.setScene(scn);
        stg.show();
    }
    public static void main(String[] args) {
        Application.launch(OldStyleJavaFXGUI.class, args);
    }
}
