JavaFX communication between controllers 📣

preview_player
Показать описание
Javafx pass values between controllers

#javafx

music credits 🎼 :
===========================================================
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
===========================================================
Рекомендации по теме
Комментарии
Автор


package application;

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


public class Main extends Application {

@Override
public void start(Stage stage) {
try {

Parent root =
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();

} catch(Exception e) {
e.printStackTrace();
}
}

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

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

<?import
<?import javafx.scene.control.Label?>
<?import
<?import
<?import javafx.scene.text.Font?>

<children>
<TextField fx:id="nameTextField" layoutX="226.0" layoutY="188.0" />
<Button fx:id="loginButton" layoutX="274.0" layoutY="246.0" mnemonicParsing="false" onAction="#login" text="login" />
<Label layoutX="81.0" layoutY="183.0" text="username:">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</AnchorPane>


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

<?import javafx.scene.control.Label?>
<?import
<?import javafx.scene.text.Font?>

<children>
<Label fx:id="nameLabel" layoutX="14.0" layoutY="14.0" text="Hello: ">
<font>
<Font size="30.0" />
</font>
</Label>
</children>
</AnchorPane>


package application;

import java.io.IOException;

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
import javafx.stage.Stage;

public class Scene1Controller {

@FXML
TextField nameTextField;

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

public void login(ActionEvent event) throws IOException {

String username = nameTextField.getText();

FXMLLoader loader = new
root = loader.load();

Scene2Controller scene2Controller = loader.getController();


//root =
stage =
scene = new Scene(root);
stage.setScene(scene);
stage.show();


}
}

package application;

import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class Scene2Controller {

@FXML
Label nameLabel;

public void displayName(String username) {
nameLabel.setText("Hello: " + username);
}

}

BroCodez
Автор

We need more javafx videos, you do the job very simple and easy to understand thanks professor

اماديرأمان
Автор

This is so much simpler than how my professor demonstrated. Thanks bro

amorfati
Автор

Once again your video saved me from missing a deadline in uni ! bro code your my favorite programing teacher

konstandinosdimitriou
Автор

Really easy to follow and informative videos about JavaFX. Thanks for making these videos

mytestaccount
Автор

This is the best Java channel I've found so far!

TheGreat
Автор

Love all your videos! There aren’t enough JAVAFX videos up!

edwardesqueda
Автор

I wish i found this video a month ago. Keep up the good work bro

Rumen
Автор

You explain so well dude! And you even go directly to the point, thanks for making my time worth :D
good job sub++ from Argentina :p

tuVja
Автор

Thanks dude, you're a god, best tutorials ever, like and recommend!

Stebandisousa
Автор

I was just searching for some Java tutorials and this channel has the best one. I am a fellow bro now :D

devguyahnaf
Автор

You saved my coding skin! Thank you so much, man!

gerdsfargen
Автор

Amazing tutorial! Thank you very much for this video

kvsw
Автор

easy and simple to follow, even one can unders
tand step without voice noted embeded

stephenkyanda
Автор

If you get an error when clicking the Login button, make sure that your Scene2.fxml document has Scene2Controller as its controller.

JefffMocha
Автор

Thanks bro! This tips is very helpful to me

minduin
Автор

hey please! how can I just get the data in the same way but to more than just one controller???
like i wanna get that same data from scene 1 to scene 2, scene 3, and scene 4 ???
please help !!

katt
Автор

From today, I'm a fellow bro :-)

sanskarsongara
Автор

What about if I want to update a method in differnt controller from another controller

اماديرأمان
Автор

I hate JavaFX. I would much rather work with Swing. It's baffling that I have to create a class, create an XML file(excuse me, an "FXML" file) for the class to load, then specify in the FXML file that I want to have these methods and objects. It's super redundant, but it's easier to update and modify than the Swing GUIs, so I guess employers like it for that reason.

socaljusticewarrior