0% found this document useful (0 votes)
104 views3 pages

Scene Builder 2

The document provides instructions for creating screens with SceneBuilder and IntelliJ IDEA. It describes how to create a JavaFX project, classes, and FXML files. It also provides sample code for linking screens, including code to load an FXML file and transition from a login screen to a database screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views3 pages

Scene Builder 2

The document provides instructions for creating screens with SceneBuilder and IntelliJ IDEA. It describes how to create a JavaFX project, classes, and FXML files. It also provides sample code for linking screens, including code to load an FXML file and transition from a login screen to a database screen.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Profa.

Tatiana Pereira Filgueiras


Lattes: http://lattes.cnpq.br/4348030324691122

Criando telas com SceneBuilder e IntelliJ IDEA

1. Abra o IntelliJ IDEA e crie um novo JAVAFX Project.


2. Crie 2 classes JAVA (Principal.java e PrincipalController.java) e um fxml (principal-view.fxml).
3. Crie 3 packages: model, view e controller. O PrincipalController.java deve estra na package
controller. O fxml deve estar na pasta view.
4. Cole o código seguinte no Principal.java, a fim de que o mesmo localize seu arquivo.fxml:

package br.com.unifebe.telasfx;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Principal extends Application {


@Override
public void start(Stage stage) throws IOException {
//new File(“src/main/java/<seu package completo incluindo o view>/<seu arquivo fxml>”)
URL url = new File("src/main/java/br/com/unifebe/telasfx/view/login-
view.fxml").toURI().toURL();
Parent root = FXMLLoader.load(url);
Scene scene = new Scene(root);
stage.setTitle("Tela de Login");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {


launch();
}
}

5. Crie sua tela de Login no seu arquivo fxml:

código:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
Profa. Tatiana Pereira Filgueiras
Lattes: http://lattes.cnpq.br/4348030324691122

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-


Infinity" prefHeight="202.0" prefWidth="398.0" xmlns="http://javafx.com/javafx/11.0.2"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="br.com.unifebe.telasfx.controller.PrincipalController">
<children>
<Button layoutX="298.0" layoutY="147.0" mnemonicParsing="false" text="Entrar">
<font>
<Font size="16.0" />
</font></Button>
<Label layoutX="69.0" layoutY="43.0" text="Login:">
<font>
<Font size="17.0" />
</font>
</Label>
<Label layoutX="63.0" layoutY="90.0" text="Senha:">
<font>
<Font size="17.0" />
</font>
</Label>
<TextField layoutX="127.0" layoutY="42.0" />
<PasswordField layoutX="127.0" layoutY="88.0" />
</children>
</AnchorPane>

6.No PincipalController.java, crie um método chamado proximaTela(ActionEvent event).

7. Crie uma nova classe (TelaBDController.java) dentro do package controller e um novo arquivo
fxml (telabd-view.fxml) dentro do package view, indicando
fx:controller="br.com.unifebe.telasfx.controller.TelaBDController".

8. Agora, vamos linkar a tela do Principal com essa nova tela. Para isso, copie e cole o código
abaixo em seu PrincipalController.java:

package br.com.unifebe.telasfx.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
Profa. Tatiana Pereira Filgueiras
Lattes: http://lattes.cnpq.br/4348030324691122

import java.net.URL;

public class PrincipalController {


private Scene scene;
private Stage stage;
private Parent root;

@FXML
private Label welcomeText;

@FXML
protected void proximaTela(ActionEvent event) throws IOException {
URL url = new File("src/main/java/br/com/unifebe/telasfx/view/telabd-
view.fxml").toURI().toURL();
this.root = FXMLLoader.load(url);
scene = new Scene(root);
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
stage.setTitle("Tela de Clientes");
stage.setScene(scene);
stage.show();
}
}

You might also like