Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sample.fxml
- <?import javafx.geometry.Insets?>
- <?import javafx.scene.layout.GridPane?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.Label?>
- <?import javafx.scene.layout.RowConstraints?>
- <?import javafx.scene.layout.ColumnConstraints?>
- <?import javafx.scene.control.TextField?>
- <GridPane fx:controller="sample.Controller"
- xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
- <rowConstraints>
- <RowConstraints/>
- <RowConstraints/>
- <RowConstraints/>
- </rowConstraints>
- <columnConstraints>
- <ColumnConstraints/>
- <ColumnConstraints/>
- </columnConstraints>
- <children>
- <!-- ovde idu FlowPane, BorderPane, HBox, etc. -->
- <Label fx:id="labelIme" style="-fx-background-color: gray;"
- GridPane.columnIndex="0" GridPane.rowIndex="0" text="Ime"/>
- <TextField fx:id="textFieldIme" promptText="Unesite ime..."
- GridPane.rowIndex="0" GridPane.columnIndex="1"/>
- <Label fx:id="labelPrezime" style="-fx-background-color: gray;"
- GridPane.columnIndex="0" GridPane.rowIndex="1" text="Prezime"/>
- <TextField fx:id="textFieldPrezime" promptText="Unesite prezime..."
- GridPane.rowIndex="1" GridPane.columnIndex="1"/>
- <Button fx:id="button1" GridPane.columnIndex="0" GridPane.rowIndex="2"
- GridPane.columnSpan="2" alignment="CENTER" onAction="#klikDugmeta" text="Klikni me"/>
- </children>
- </GridPane>
- // Controller.java
- package sample;
- import javafx.event.ActionEvent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.BorderPane;
- public class Controller {
- // Može se dodati ovde '@FXML', ali ne mora - bitno je uklopiti imena promenljivih
- public Label labelIme, labelPrezime;
- public TextField textFieldIme, textFieldPrezime;
- public Button button1;
- public void klikDugmeta(ActionEvent actionEvent) {
- BorderPane borderPane = new BorderPane();
- borderPane.setLeft(new Label("Ime: " + textFieldIme.getText()));
- borderPane.setRight(new Label("Prezime: " + textFieldPrezime.getText()));
- Scene scene = new Scene(borderPane, 400, 400);
- Main.promeniScenu(scene);
- }
- }
- // Main.java
- package sample;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Group;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class Main extends Application {
- private static Stage stage;
- public static void promeniScenu(Scene scene){
- stage.setScene(scene);
- }
- @Override
- public void start(Stage primaryStage) throws Exception{
- stage = primaryStage;
- Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
- Scene scene = new Scene(root, 400, 400);
- primaryStage.setTitle("Vežba 12");
- primaryStage.setScene(scene);
- primaryStage.show();
- /*
- // SEKCIJA BEZ FXML-a
- primaryStage.setTitle("Vežba 12");
- BorderPane borderPane = new BorderPane();
- Button button = new Button("Pri'cni me!");
- button.setOnAction(event -> {
- primaryStage.setTitle("Vežba 12 - At a beauty center...");
- borderPane.setStyle("-fx-background-color: aqua;");
- });
- borderPane.setBottom(button);
- // VBOX
- VBox vBox = new VBox(10);
- // vBox.setPadding(new Insets(10));
- RadioButton radioButton1 = new RadioButton("Izbor 1");
- radioButton1.setOnAction(event -> {
- borderPane.setStyle("-fx-background-color: teal;");
- });
- RadioButton radioButton2 = new RadioButton("Izbor 2");
- radioButton2.setOnAction(event -> {
- borderPane.setStyle("-fx-background-color: pink;");
- });
- RadioButton radioButton3 = new RadioButton("Izbor 3");
- radioButton3.setOnAction(event -> {
- borderPane.setStyle("-fx-background-color: orange;");
- });
- ToggleGroup toggleGroup = new ToggleGroup();
- radioButton1.setToggleGroup(toggleGroup);
- radioButton2.setToggleGroup(toggleGroup);
- radioButton3.setToggleGroup(toggleGroup);
- vBox.getChildren().addAll(radioButton1, radioButton2, radioButton3);
- borderPane.setLeft(vBox);
- // END OF vBOX
- // HBOX
- HBox hBox = new HBox(10);
- CheckBox checkbox1 = new CheckBox("Izbor 1");
- CheckBox checkbox2 = new CheckBox("Izbor 2");
- CheckBox checkbox3 = new CheckBox("Izbor 3");
- hBox.getChildren().addAll(checkbox1, checkbox2, checkbox3);
- borderPane.setRight(hBox);
- // END OF HBOX
- // GRID PANE
- GridPane gridPane = new GridPane();
- gridPane.add(new Label("Ime"), 0, 0);
- TextField textFieldIme = new TextField();
- textFieldIme.setPromptText("Unesite ime...");
- gridPane.add(textFieldIme, 1, 0);
- gridPane.add(new Label("Prezime"), 0, 1);
- TextField textFieldPrezime = new TextField();
- textFieldPrezime.setPromptText("Unesite prezime...");
- gridPane.add(textFieldPrezime, 1, 1);
- borderPane.setCenter(gridPane);
- // END OF GRIDPANE
- Scene scene = new Scene(borderPane, 500, 500);
- primaryStage.setScene(scene);
- primaryStage.show();
- */
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement