Package belotetime.core.dialog

Source Code of belotetime.core.dialog.AskBox

package belotetime.core.dialog;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

@SuppressWarnings("rawtypes")
public class AskBox extends Stage implements EventHandler{
  private Button _yesButton, _noButton;
  private static Boolean _answer;

  public static Boolean Show(String title, String question){
    _answer = null;
    (new AskBox(title, question)).showAndWait();
    return _answer;
  }
 
  @SuppressWarnings("unchecked")
  public AskBox(String title, String question){
    setTitle(title);
    initStyle(StageStyle.UTILITY);
        initModality(Modality.APPLICATION_MODAL);
       
        setResizable(false);

    Insets insets = new Insets(5, 5, 5, 5);
   
    BorderPane border = new BorderPane();
   
    Label _questionLabel = new Label();
    _questionLabel.setText(question);
    border.setCenter(_questionLabel);
    BorderPane.setMargin(_questionLabel, insets);
   
    FlowPane flow = new FlowPane();
    flow.setAlignment(Pos.CENTER);
   
    _yesButton = new Button("Oui");
    _yesButton.setOnAction(this);
    FlowPane.setMargin(_yesButton, insets);
    flow.getChildren().add(_yesButton);
   
    _noButton = new Button("Non");
    _noButton.setOnAction(this);
    FlowPane.setMargin(_noButton, insets);
    flow.getChildren().add(_noButton);
       
    border.setBottom(flow);
   
    Scene scene = new Scene(border);
    setScene(scene);
  }

    public void showDialog() {
        sizeToScene();
        centerOnScreen();
        showAndWait();
    }
 
  @Override
  public void handle(Event arg0) {
    if (arg0.getSource() == _yesButton) {
      _answer = true;
      hide();
    } else if(arg0.getSource() == _noButton){
      _answer = false;
      hide();
    }
  }

}
TOP

Related Classes of belotetime.core.dialog.AskBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.