Advertisement
sdee3

OBP2 - v12

Jan 16th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.79 KB | None | 0 0
  1. // sample.fxml
  2.  
  3. <?import javafx.geometry.Insets?>
  4. <?import javafx.scene.layout.GridPane?>
  5.  
  6. <?import javafx.scene.control.Button?>
  7. <?import javafx.scene.control.Label?>
  8. <?import javafx.scene.layout.RowConstraints?>
  9. <?import javafx.scene.layout.ColumnConstraints?>
  10. <?import javafx.scene.control.TextField?>
  11. <GridPane fx:controller="sample.Controller"
  12.           xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
  13.     <rowConstraints>
  14.         <RowConstraints/>
  15.         <RowConstraints/>
  16.         <RowConstraints/>
  17.     </rowConstraints>
  18.  
  19.     <columnConstraints>
  20.         <ColumnConstraints/>
  21.         <ColumnConstraints/>
  22.     </columnConstraints>
  23.  
  24.     <children>
  25.         <!-- ovde idu FlowPane, BorderPane, HBox, etc. -->
  26.  
  27.         <Label fx:id="labelIme" style="-fx-background-color: gray;"
  28.                GridPane.columnIndex="0" GridPane.rowIndex="0" text="Ime"/>
  29.         <TextField fx:id="textFieldIme" promptText="Unesite ime..."
  30.                    GridPane.rowIndex="0" GridPane.columnIndex="1"/>
  31.  
  32.  
  33.         <Label fx:id="labelPrezime" style="-fx-background-color: gray;"
  34.                GridPane.columnIndex="0" GridPane.rowIndex="1" text="Prezime"/>
  35.         <TextField fx:id="textFieldPrezime" promptText="Unesite prezime..."
  36.                    GridPane.rowIndex="1" GridPane.columnIndex="1"/>
  37.  
  38.         <Button fx:id="button1" GridPane.columnIndex="0" GridPane.rowIndex="2"
  39.                 GridPane.columnSpan="2" alignment="CENTER" onAction="#klikDugmeta" text="Klikni me"/>
  40.     </children>
  41. </GridPane>
  42.  
  43. // Controller.java
  44.  
  45. package sample;
  46.  
  47. import javafx.event.ActionEvent;
  48. import javafx.scene.Scene;
  49. import javafx.scene.control.Button;
  50. import javafx.scene.control.Label;
  51. import javafx.scene.control.TextField;
  52. import javafx.scene.layout.BorderPane;
  53.  
  54. public class Controller {
  55.     // Može se dodati ovde '@FXML', ali ne mora - bitno je uklopiti imena promenljivih
  56.     public Label labelIme, labelPrezime;
  57.     public TextField textFieldIme, textFieldPrezime;
  58.     public Button button1;
  59.  
  60.     public void klikDugmeta(ActionEvent actionEvent) {
  61.         BorderPane borderPane = new BorderPane();
  62.         borderPane.setLeft(new Label("Ime: " + textFieldIme.getText()));
  63.         borderPane.setRight(new Label("Prezime: " + textFieldPrezime.getText()));
  64.  
  65.         Scene scene = new Scene(borderPane, 400, 400);
  66.         Main.promeniScenu(scene);
  67.     }
  68. }
  69.  
  70. // Main.java
  71.  
  72. package sample;
  73.  
  74. import javafx.application.Application;
  75. import javafx.event.ActionEvent;
  76. import javafx.event.EventHandler;
  77. import javafx.fxml.FXMLLoader;
  78. import javafx.scene.Group;
  79. import javafx.scene.Parent;
  80. import javafx.scene.Scene;
  81. import javafx.scene.control.*;
  82. import javafx.scene.layout.BorderPane;
  83. import javafx.scene.layout.GridPane;
  84. import javafx.scene.layout.HBox;
  85. import javafx.scene.layout.VBox;
  86. import javafx.stage.Stage;
  87.  
  88. public class Main extends Application {
  89.     private static Stage stage;
  90.  
  91.     public static void promeniScenu(Scene scene){
  92.         stage.setScene(scene);
  93.     }
  94.  
  95.     @Override
  96.     public void start(Stage primaryStage) throws Exception{
  97.         stage = primaryStage;
  98.         Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
  99.         Scene scene = new Scene(root, 400, 400);
  100.         primaryStage.setTitle("Vežba 12");
  101.         primaryStage.setScene(scene);
  102.         primaryStage.show();
  103.  
  104.  
  105.  
  106.  
  107. /*
  108. // SEKCIJA BEZ FXML-a
  109.         primaryStage.setTitle("Vežba 12");
  110.  
  111.         BorderPane borderPane = new BorderPane();
  112.         Button button = new Button("Pri'cni me!");
  113.         button.setOnAction(event -> {
  114.             primaryStage.setTitle("Vežba 12 - At a beauty center...");
  115.             borderPane.setStyle("-fx-background-color: aqua;");
  116.         });
  117.  
  118.         borderPane.setBottom(button);
  119. // VBOX
  120.         VBox vBox = new VBox(10);
  121.         // vBox.setPadding(new Insets(10));
  122.  
  123.         RadioButton radioButton1 = new RadioButton("Izbor 1");
  124.         radioButton1.setOnAction(event -> {
  125.             borderPane.setStyle("-fx-background-color: teal;");
  126.         });
  127.         RadioButton radioButton2 = new RadioButton("Izbor 2");
  128.         radioButton2.setOnAction(event -> {
  129.             borderPane.setStyle("-fx-background-color: pink;");
  130.         });
  131.         RadioButton radioButton3 = new RadioButton("Izbor 3");
  132.         radioButton3.setOnAction(event -> {
  133.             borderPane.setStyle("-fx-background-color: orange;");
  134.         });
  135.  
  136.         ToggleGroup toggleGroup = new ToggleGroup();
  137.         radioButton1.setToggleGroup(toggleGroup);
  138.         radioButton2.setToggleGroup(toggleGroup);
  139.         radioButton3.setToggleGroup(toggleGroup);
  140.  
  141.         vBox.getChildren().addAll(radioButton1, radioButton2, radioButton3);
  142.  
  143.         borderPane.setLeft(vBox);
  144. // END OF vBOX
  145. // HBOX
  146.         HBox hBox = new HBox(10);
  147.  
  148.         CheckBox checkbox1 = new CheckBox("Izbor 1");
  149.         CheckBox checkbox2 = new CheckBox("Izbor 2");
  150.         CheckBox checkbox3 = new CheckBox("Izbor 3");
  151.  
  152.         hBox.getChildren().addAll(checkbox1, checkbox2, checkbox3);
  153.  
  154.         borderPane.setRight(hBox);
  155. // END OF HBOX
  156. // GRID PANE
  157.         GridPane gridPane = new GridPane();
  158.  
  159.         gridPane.add(new Label("Ime"), 0, 0);
  160.  
  161.         TextField textFieldIme = new TextField();
  162.         textFieldIme.setPromptText("Unesite ime...");
  163.         gridPane.add(textFieldIme, 1, 0);
  164.  
  165.         gridPane.add(new Label("Prezime"), 0, 1);
  166.  
  167.         TextField textFieldPrezime = new TextField();
  168.         textFieldPrezime.setPromptText("Unesite prezime...");
  169.         gridPane.add(textFieldPrezime, 1, 1);
  170.  
  171.         borderPane.setCenter(gridPane);
  172. // END OF GRIDPANE
  173.         Scene scene = new Scene(borderPane, 500, 500);
  174.         primaryStage.setScene(scene);
  175.         primaryStage.show();
  176. */
  177.     }
  178.  
  179.     public static void main(String[] args) {
  180.         launch(args);
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement