package cap3;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class AddSubtract5 extends Application{

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

    Button btnAdd;
    Button btnSubtract;
    Label lbl;
    int iCount;

    @Override
    public void start(Stage primaryStage) throws Exception {

        //Create add button
        btnAdd = new Button("+");
        btnAdd.setOnAction(event -> btnAddClick());

        //Create subtract button
        btnSubtract = new Button("-");
        btnSubtract.setOnAction(event -> btnSubtractClick());

        //Create the Label
        lbl = new Label();
        lbl.setText(Integer.toString(iCount));

        //Add the buttons and the label to an HBox pane
        HBox pane = new HBox();
        pane.getChildren().addAll(btnAdd, btnSubtract, lbl);

        //Create a scene
        Scene scene = new Scene(pane, 300, 250);

        //Add the scene to the Stage
        primaryStage.setScene(scene);
        primaryStage.setTitle("Add/Sub");
        primaryStage.initStyle(StageStyle.UTILITY);
        primaryStage.show();

    }

    private void btnAddClick(){
        lbl.setText(Integer.toString(++iCount));
    }

    private void btnSubtractClick(){
        lbl.setText(Integer.toString(--iCount));
    }

}//fim AddSubtract5
