Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui.pizza;
- import javafx.application.Application;
- import javafx.scene.Node;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.RadioButton;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.ToggleGroup;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public final class Pizza extends Application {
- private Configuration config = new Configuration();
- private GridPane checkPane, radioPane;
- private TextArea summary;
- public void start(Stage primStage) {
- GridPane root = new GridPane();
- checkPane = new GridPane();
- radioPane = new GridPane();
- Scene scene = new Scene(root, 640, 480);
- primStage.setScene(scene);
- primStage.show();
- root.add(checkPane, 0, 0);
- root.add(radioPane, 0, 1);
- String[] list = config.getToppingNames();
- for (int a = 0, i = 0; i < list.length; i++) {
- a = i % 2;
- CheckBox tmpChk = new CheckBox(list[i]);
- if (i < config.getNumberOfDefaultToppings()) {
- tmpChk.setDisable(true);
- tmpChk.setSelected(true);
- }
- checkPane.add(tmpChk, a, i - a);
- }
- list = config.getSizeNames();
- ToggleGroup tglGrp = new ToggleGroup();
- for (int i = 0; i < list.length; i++) {
- RadioButton tmpButton = new RadioButton((list[i]));
- tmpButton.setToggleGroup(tglGrp);
- radioPane.add(tmpButton, i, 0);
- }
- Button orderButton = new Button("Bestellen");
- orderButton.setOnAction(e -> order());
- summary = new TextArea("");
- summary.setEditable(false);
- root.add(orderButton, 0, 2);
- root.add(summary, 0, 3);
- }
- public static void main(String[] args) {
- launch(args);
- }
- private void order() {
- boolean sizePressed = false;
- for (Node radBtn : radioPane.getChildren()) {
- sizePressed = (((RadioButton) radBtn).isSelected()) ? true : sizePressed;
- }
- if (sizePressed) {
- StringBuffer str = new StringBuffer();
- str.append("Sie haben eine Pizza bestellt!\nZutaten: ");
- for (Node node : checkPane.getChildren()) {
- CheckBox check = (CheckBox) node;
- str.append((check.isSelected()) ? (check.getText() + ", ") : "");
- }
- str.setLength(str.length() - 1);
- RadioButton activeButton = (RadioButton) ((RadioButton) radioPane.getChildren().get(0)).getToggleGroup().getSelectedToggle();
- str.append("\nDie Größe ist: " + activeButton.getText());
- str.append("\nVielen Dank.");
- summary.setText(str.toString());
- } else {
- summary.setText("Bitte wählen Sie eine Pizzagröße");
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement