Description Using JavaFX and any of its associated controls

Description
Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media players, or other devices. You may choose any object as long as you fulfill the requirements.
Your interface should use a minimum of:
5 UI Components (e.g. Button, Label, TextField, etc.)
3 different types of Panes
o At least one Pane must contain another Pane (e.g. FlowPane containing a VBox)
1 bound property
Node property customization
Optional, but useful:
Image/ImageView, counts (combined) as 1 of the 5 UI components if used
Other requirements and notes:
Your program should indicate, in the comment header, the object you are recreating. If the object you are using is not common, include a link to a representative picture.
A portion of your grade will be based on how well the program represents the object you are emulating, within the limits of JavaFX.
o Effective use of images will help here greatly
This is a purely visual assignment; there is no interactive requirement.
Sketching the object will help you figure out which types of panes to use.

Solution

import javafx.application.Application;

import javafx.beans.binding.Bindings;

import javafx.beans.property.*;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.*;

import javafx.scene.input.KeyEvent;

import javafx.scene.layout.*;

import javafx.stage.Stage;

import javafx.stage.StageStyle;

import java.util.HashMap;

import java.util.Map;

//creation of class

public class Calculator10 extends Application {

// declaring the different numbers and the symbols on the calculator

// declaring the variables as static

private static final String[][] staticcalcval = {

      { \"7\", \"8\", \"9\", \"/\" },

      { \"4\", \"5\", \"6\", \"*\" },

      { \"1\", \"2\", \"3\", \"-\" },

      { \"0\", \"c\", \"=\", \"+\" }

}; // declaring as final as values would not be changed

//creating a hashmap which has a key and a value in it.

private final Map<String, Button> accelerators = new HashMap<>();

private DoubleProperty stackValue = new SimpleDoubleProperty();

private DoubleProperty value = new SimpleDoubleProperty();

//creation of enum for performing operations - addition, subtraction, multiplication and division.

private enum Op { NOOP, ADD, SUBTRACT, MULTIPLY, DIVIDE }

private Op curOp   = Op.NOOP;

private Op stackOp = Op.NOOP;

//main method

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

//overriding class Stage

@Override public void start(Stage stage) {

    final TextField screen = createScreen();

    final TilePane buttons = createButtons();

//using properties of class Class(title, resize property, style, setting scene)

    stage.setTitle(\"Calculator10\");

    stage.initStyle(StageStyle.UTILITY);

    stage.setResizable(false);

    stage.setScene(new Scene(createLayout(screen, buttons)));

    stage.show();

}

//Pane1

//Creation of a Text field and Pane

//creating a Layout

private VBox createLayoutnew(TextField screen, TilePane buttons) {

    final VBox layout = new VBox(20);

//alignment property

    layout.setAlignment(Pos.CENTER);

    layout.setStyle(\"-fx-background-color: chocolate; -fx-padding: 20; -fx-font-size: 20;\");

    layout.getChildren().setAll(screen, buttons);

    handleAccelerators(layout);

//setting the width of the screen

    screen.prefWidthProperty().bind(buttons.widthProperty());

    return layout;

//retunring the layout

}

private void handleAccelerators(VBox layout) {

    layout.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

   

//handle event

@Override

      public void handle10(KeyEvent keyEvent) {

        Button activated = accelerators.get(keyEvent.getText());

        if (activated != null) {

          activated.fire();

        }

      }

    });

}

//creation of Txtfield

private TextField createScreen() {

    final TextField screen = new TextField();

//setting the properties of text field, alignment, background color, iniitally text box is disabled

    screen.setStyle(\"-fx-background-color: aquamarine;\");

    screen.setAlignment(Pos.CENTER_RIGHT);

    screen.setEditable(false);

    screen.textProperty().bind(Bindings.format(\"%.0f\", value));

    return screen;

}

//Pane2

private TilePane createButtons() {

    TilePane buttons = new TilePane();

    buttons.setVgap(7);

    buttons.setHgap(7);

   buttons.setPrefColumns(static[0].length);

    for (String[] r: staticcalcval) {

      for (String s: r) {            

        buttons.getChildren().add(createButton(s));

//calling the button methods

      }

    }

//returning the value for buttonww v gt

    return buttons;

}

//creation of object – ‘button’

private Button createButton(final String s) // passing a string variable declaring as final, so that no modifications are made ot it,

{

    Button button = makeStandardButton(s);

//code snippet to check the existence of valid numeric keys

// verifying the number keys on the calculator

   if (s.matches(\"[0-9]\")) {

      makeNumericButton(s, button);

    } else {

      final ObjectProperty<Op> triggerOp = determineOperand(s);

      if (triggerOp.get() != Op.NOOP) {

        makeOperandButtonactive(button, triggerOp);

      } else if (\"c\".equals(s)) {

        makeClearButton(button);

      } else if (\"=\".equals(s)) {   //checking the ‘if ele’ condition

        makeEqualsButton(button);

      }

    }

    return button;

  }

//usage of switch case

private ObjectProperty<Op> determineOperand(String s) {

    final ObjectProperty<Op> triggerOp = new SimpleObjectProperty<>(Op.NOOP);

    switch (s) {

      case \"+\": triggerOp.set(Op.ADD);      break;

      case \"-\": triggerOp.set(Op.SUBTRACT); break;

      case \"*\": triggerOp.set(Op.MULTIPLY); break;

      case \"/\": triggerOp.set(Op.DIVIDE);   break;

    }

    return triggerOp;

}

private void makeOperandButtonactive(Button button, final ObjectProperty<Op> triggerOp) {

    button.setStyle(\"-fx-base: lightgray;\");

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

      @Override

//overriding ActionEvent method

      public void handle(ActionEvent actionEvent) {

        curOp = triggerOp.get();

      }

    });

}

private Button makeStandardButton(String s) {

    Button button = new Button(s);

    button.setStyle(\"-fx-base: beige;\");

    accelerators.put(s, button);

    button.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

    return button;

}

private void makeNumericButton(final String s, Button button) {

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

      @Override

      public void handle(ActionEvent actionEvent) {

        if (curOp == Op.NOOP) {

          value.set(value.get() * 10 + Integer.parseInt(s));

        } else {

          stackValue.set(value.get());

          value.set(Integer.parseInt(s));

          stackOp = curOp;

          curOp = Op.NOOP;

        }

      }

    });

}

private void makeClearButton(Button button) {

    button.setStyle(\"-fx-base: mistyrose;\");

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

      @Override // overriding ActionEvent method

      public void handle(ActionEvent actionEvent) {

        value.set(0);

      }

    });

}

private void makeEqualsButton(Button button) {

    button.setStyle(\"-fx-base: ghostwhite;\");

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

      @Override

      public void handle(ActionEvent actionEvent) {

        switch (stackOp) {

          case ADD:      value.set(stackValue.get() + value.get()); break;

          case SUBTRACT: value.set(stackValue.get() - value.get()); break;

          case MULTIPLY: value.set(stackValue.get() * value.get()); break;

          case DIVIDE:   value.set(stackValue.get() / value.get()); break;

        }

      }

    });

}

}

Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media
Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media
Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media
Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media
Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media
Description Using JavaFX and any of its associated controls, recreate an interface. Examples include items like microwaves, calculators, ATMs, car radios, media

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site