Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guifx;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- public class ProduktInputWindow extends Stage {
- public ProduktInputWindow(String title, Stage owner) {
- this.initOwner(owner);
- this.initStyle(StageStyle.UTILITY);
- this.initModality(Modality.APPLICATION_MODAL);
- this.setMinHeight(100);
- this.setMinWidth(200);
- this.setResizable(false);
- this.setTitle(title);
- GridPane pane = new GridPane();
- this.initContent(pane);
- Scene scene = new Scene(pane);
- this.setScene(scene);
- }
- // -------------------------------------------------------------------------
- private TextField txfNavn;
- private TextField txfMængde;
- private Produkt actualProdukt = null;
- private void initContent(GridPane pane) {
- // pane.setGridLinesVisible(true);
- pane.setPadding(new Insets(20));
- pane.setHgap(10);
- pane.setVgap(10);
- Label lblNavn = new Label("Navn :");
- pane.add(lblNavn, 0, 0);
- Label lblMængde = new Label("Mængde :");
- pane.add(lblMængde, 0, 2);
- txfNavn = new TextField();
- pane.add(txfNavn, 1, 0, 2, 1);
- txfMængde = new TextField();
- pane.add(txfMængde, 1, 1, 2, 1);
- HBox buttonBox = new HBox(20);
- pane.add(buttonBox, 0, 3);
- buttonBox.setPadding(new Insets(10, 10, 0, 10));
- buttonBox.setAlignment(Pos.TOP_RIGHT);
- Button btnCancel = new Button("Cancel");
- buttonBox.getChildren().add(btnCancel);
- btnCancel.setOnAction(event -> this.cancelAction());
- Button btnOK = new Button("OK");
- buttonBox.getChildren().add(btnOK);
- btnOK.setOnAction(event -> this.okAction());
- }
- // -------------------------------------------------------------------------
- // -------------------------------------------------------------------------
- // Button actions
- private void cancelAction() {
- txfNavn.clear();
- txfNavn.requestFocus();
- txfMængde.clear();
- actualProdukt = null;
- ProduktInputWindow.this.hide();
- }
- private void okAction() {
- String navn = txfNavn.getText().trim();
- String mængde = txfMængde.getText().trim();
- if (navn.length() > 0 && mængde.length() > 0) {
- actualProdukt = new Produkt(navn, mængde);
- txfNavn.clear();
- txfMængde.clear();
- txfNavn.requestFocus();
- ProduktInputWindow.this.hide();
- } else {
- Alert alert = new Alert(AlertType.INFORMATION);
- alert.setTitle("Create Produkt");
- alert.setHeaderText("Information missing");
- alert.setContentText("Indtast navn og Mængde");
- alert.show();
- }
- }
- public Produkt getActualProdukt() {
- return actualProdukt;
- }
- public void clearActualMovie() {
- actualProdukt = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement