import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.text.*;                             //for Text class
import javafx.collections.*;                            //for ObservableList 

public class Awindow4 extends Application  
{
    @Override
    public void start(Stage win) throws Exception 
    {
        win.setTitle("Window using GridPane layout with internal CSS");

        Text title = new Text("My Application");
        
        MenuBar  menus = new MenuBar();                             //create a menu bar
        Menu     menu1 = new Menu("File");                          //create a menu
        MenuItem open  = new MenuItem("Open");                      //create a menu item
        MenuItem save  = new MenuItem("Save");
        MenuItem print = new MenuItem("Print");
        MenuItem exit  = new MenuItem("Exit");
        Menu     menu2 = new Menu("Edit");
        MenuItem find  = new MenuItem("Find");
        MenuItem rplc  = new MenuItem("Replace");
        MenuItem copy  = new MenuItem("Copy");
        MenuItem paste = new MenuItem("Paste");
                
        menu1.getItems().addAll(open,save,print,exit);              //add menu items in menu
        menu2.getItems().addAll(find,rplc,copy,paste);
        menus.getMenus().addAll(menu1,menu2);                       //add menus in menu bar

        Label     label1 = new Label("Enter Name    ");             //create a label
        TextField field1 = new TextField("Sam Sultan");             //create a textfield with initial value                
        Label     label2 = new Label("Comment");
        TextArea  field2 = new TextArea("line1 \n line2");          //create a textarea with initial values            

        RadioButton radio1 = new RadioButton("Male");               //create a radio buttoon
        RadioButton radio2 = new RadioButton("Female");
        ToggleGroup radioGroup = new ToggleGroup();                 //create a radio group
        radio1.setToggleGroup(radioGroup);                          //add radio button to radio group
        radio2.setToggleGroup(radioGroup);
        radio1.setSelected(true);
        
        CheckBox check1 = new CheckBox("Red");                      //create a check box
        CheckBox check2 = new CheckBox("Blue");
        check1.setSelected(true);

        ChoiceBox<String> select = new ChoiceBox<String>();             //single dropdown select list
        select.getItems().add("High School");
        select.getItems().add("Bachelor");
        select.getItems().add("Master");
        select.getItems().add("PHD");
        select.getSelectionModel().select(0);
 
        ListView<String> mSelect = new ListView<String>();              //multiple scrollable select list
        String[] animals = {"Dogs","Cats","Birds","Fish","Turtles","Other"};
        ObservableList<String> list = FXCollections.observableArrayList(animals);
        mSelect.setItems(list);
        mSelect.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

        Button submit = new Button(" Submit ");
        Button cancel = new Button(" Cancel ");
 
        Region vSpace = new Region();                   //create a region
        Region space1 = new Region();                   //width/height will be set in CSS below
        Region space2 = new Region();                   
        Region space3 = new Region();
 
        GridPane pane = new GridPane();                 //create a grid layout manager
        
        pane.add(menus,  0,0);                          //add components to layout manager
        pane.add(title,  2,0,4,1);                      //component,col,row,colspan,colspan
        pane.add(vSpace, 0,1);                           
        pane.add(label1, 0,2);                           
        pane.add(field1, 1,2,9,1);                       
        pane.add(label2, 0,3);                     
        pane.add(field2, 1,3,9,1);
        pane.add(radio1, 1,4);
        pane.add(radio2, 2,4);
        pane.add(space1, 3,4);
        pane.add(check1, 4,4);
        pane.add(check2, 5,4);
        pane.add(space2, 6,4);
        pane.add(select, 7,4);
        pane.add(space3, 8,4);
        pane.add(mSelect,9,4);
        pane.add(submit, 1,5);
        pane.add(cancel, 2,5);
           
//----- Styling with CSS --------------------
        pane.setStyle  ("-fx-font-weight:bold;   -fx-background-color:lightyellow;"   
                      + "-fx-hgap:5; -fx-vgap:5; -fx-padding:10 0 0 5;");            //padding:top,right,bottom,left
        title.setStyle ("-fx-font:bold 20px 'Verdana'; -fx-fill:blue;");
        vSpace.setStyle("-fx-min-height:10px;");
        label1.setStyle("-fx-font-size:14px;");
        label2.setStyle("-fx-font-size:14px;");
        mSelect.setStyle("-fx-max-width:95px; -fx-pref-height:25px");
        submit.setStyle("-fx-background-color:green; -fx-text-fill:white; -fx-cursor:hand; -fx-background-radius:10");
        cancel.setStyle("-fx-background-color:red;   -fx-text-fill:white; -fx-cursor:hand; -fx-background-radius:10");
        space1.setStyle("-fx-min-width:20;");
        space2.setStyle("-fx-min-width:20;");
        space3.setStyle("-fx-min-width:20;");
//----- Styling with CSS --------------------

        Scene scene = new Scene(pane, 650, 350); 
        
        win.setScene(scene);
        win.show();
    }

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