Skip to content
Snippets Groups Projects
Controller.java 3.3 KiB
Newer Older
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;

public class Controller {

Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
    private Label output;

Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
    @FXML
    private Button one;
    @FXML
    private Button two;
    @FXML
    private Button three;
    @FXML
    private Button four;
    @FXML
    private Button five;
    @FXML
    private Button six;
    @FXML
    private Button seven;
    @FXML
    private Button eight;
    @FXML
    private Button nine;
    @FXML
    private Button zero;

    /*
     *  the function reacts on clicked Buttons
     */
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
    private void setButtons(){
        one.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "1");
            }
            
        });

        two.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "2");
            }
            
        });

        three.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "3");
            }
            
        });

        four.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "4");
            }
            
        });

        five.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "5");
            }
            
        });

        six.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "6");
            }
            
        });

        seven.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "7");
            }
            
        });

        eight.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "8");
            }
            
        });

        nine.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "9");
            }
            
        });

        zero.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event){
                output.setText(output.getText()+ "0");
            }
            
        });

    }

    public void initialize() {
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed
        // output.setText("No Input");
        output.setBackground(new Background(new BackgroundFill(Color.WHEAT, CornerRadii.EMPTY, Insets.EMPTY)));
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed

        setButtons();
Kyrylo Lipkovych's avatar
Kyrylo Lipkovych committed