JavaFX communication between controllers 📣

Поділитися
Вставка
  • Опубліковано 21 сер 2024
  • Javafx pass values between controllers
    #javafx
    music credits 🎼 :
    ===========================================================
    Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
    Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
    Free Download / Stream: bit.ly/2JnDfCE
    Music promoted by Audio Library • Up In My Jam (All Of A...
    ===========================================================

КОМЕНТАРІ • 91

  • @BroCodez
    @BroCodez  3 роки тому +42

    //-----------------------------------------Main.java--------------------------------------------
    package application;

    import javafx.application.Application;
    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 = FXMLLoader.load(getClass().getResource("Scene1.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    } catch(Exception e) {
    e.printStackTrace();
    }
    }
    public static void main(String[] args) {
    launch(args);
    }
    }
    //-----------------------------------------Scene1.fxml-----------------------------------------









    //-----------------------------------------Scene2.fxml-----------------------------------------







    //----------------------------------Scene1Controller.java-----------------------------------
    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 javafx.scene.control.TextField;
    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 FXMLLoader(getClass().getResource("Scene2.fxml"));
    root = loader.load();

    Scene2Controller scene2Controller = loader.getController();
    scene2Controller.displayName(username);

    //root = FXMLLoader.load(getClass().getResource("Scene2.fxml"));
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    }
    }
    //----------------------------------Scene2Controller.java-----------------------------------
    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);
    }

    }
    //--------------------------------------------------------------------------------------------------

    • @tuV13ja
      @tuV13ja 3 роки тому +2

      Can you make a video about good practices/design patterns for data validation from UI and comunication with business logic ???? I've never seen a video about it, so you can be the chosen one for this job :')

  • @user-ts6nf9st4c
    @user-ts6nf9st4c 2 роки тому +20

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

  • @devguyahnaf
    @devguyahnaf 3 роки тому +13

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

    • @user-ts6nf9st4c
      @user-ts6nf9st4c 2 роки тому

      It's true ,it brings me a lot Just fellow lessons

  • @amorfati4559
    @amorfati4559 3 роки тому +4

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

  • @TheGreat8220
    @TheGreat8220 2 роки тому

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

  • @lequangnghi194
    @lequangnghi194 Рік тому +3

    I don't know why I run into a NullPointerException at this line of code:
    scene2Controller.displayName(userName);
    Edit: Never mind! I just forgot to add Controller class

  • @konstandinosdimitriou2301
    @konstandinosdimitriou2301 8 місяців тому

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

  • @mytestaccount23
    @mytestaccount23 Рік тому +2

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

  • @edwardesqueda4759
    @edwardesqueda4759 3 роки тому +3

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

  • @Rumen35
    @Rumen35 3 роки тому +1

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

  • @Stebandisousa
    @Stebandisousa 2 роки тому

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

  • @tuV13ja
    @tuV13ja 3 роки тому +2

    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

  • @gerdsfargen6687
    @gerdsfargen6687 11 місяців тому

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

  • @brandonjablasone7544
    @brandonjablasone7544 6 місяців тому

    Bro you are really the goat

  • @kvsw6296
    @kvsw6296 3 роки тому +1

    Amazing tutorial! Thank you very much for this video

  • @amir_edlbi
    @amir_edlbi 2 роки тому +1

    You saved me. Thanks a lot.

  • @HeluAcademyXBrainBoosters
    @HeluAcademyXBrainBoosters 3 роки тому +1

    I am a fellow bro ....Yes boss

  • @MrPlaybook
    @MrPlaybook Місяць тому

    Bro adamdır!

  • @umarqazi9113
    @umarqazi9113 Рік тому

    Best one out there!

  • @chemso_1
    @chemso_1 4 місяці тому

    da best

  • @JefffMocha
    @JefffMocha 2 місяці тому

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

  • @stephenkyanda8311
    @stephenkyanda8311 Рік тому

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

  • @sanskarsongara2592
    @sanskarsongara2592 3 роки тому +1

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

  • @minduin90
    @minduin90 2 роки тому

    Thanks bro! This tips is very helpful to me

  • @mohamadghobadi5043
    @mohamadghobadi5043 3 роки тому

    Excellent Useful Thank you very much

  • @wolanus
    @wolanus 3 роки тому

    Great video!

  • @igorsantanas
    @igorsantanas 2 роки тому

    Thanks Bro, that helps a lot!

  • @MrDritzii
    @MrDritzii 3 роки тому +1

    love you bro

  • @Mars-sm
    @Mars-sm 10 місяців тому

    Thank you, bro!

  • @deividimizael
    @deividimizael 8 місяців тому

    Thanks, I Love you

  • @arshahin9803
    @arshahin9803 2 роки тому

    awesome!

  • @ashkanshakiba9579
    @ashkanshakiba9579 3 роки тому

    Useful 👌👍

  • @amadoutraore1967
    @amadoutraore1967 2 місяці тому

    Thank you bro

  • @ICantCodeYet
    @ICantCodeYet 3 місяці тому

    I love Bro Code

  • @tharinmahale9878
    @tharinmahale9878 3 роки тому

    Thanks this helped me alot

  • @vincentparkes2513
    @vincentparkes2513 10 місяців тому

    Nice🙂

  • @Not_Yukii
    @Not_Yukii 2 роки тому

    Thanks you so much !

  • @kimevar
    @kimevar 3 роки тому

    Nice video

  • @shahzaibmalik9264
    @shahzaibmalik9264 3 роки тому +1

    thanks bro

  • @socaljusticewarrior558
    @socaljusticewarrior558 Рік тому +3

    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.

  • @MrsAhmed-lr1sp
    @MrsAhmed-lr1sp Рік тому

    nice show()

  • @AI-lf7fl
    @AI-lf7fl 3 роки тому +1

    I'm a faaaan of yours

  • @mcfrizzlefries5537
    @mcfrizzlefries5537 3 роки тому

    Hell yeah, thanks bro code

  • @mohamadghobadi5043
    @mohamadghobadi5043 3 роки тому

    Please be the next media player tutorial (audio and video) I will only learn from your channel

  • @Dswilsonangel
    @Dswilsonangel 2 роки тому

    Thanks!!!!!!!!!😁

  • @hamzachiguer642
    @hamzachiguer642 Рік тому

    thank you bro

  • @xXEkoLogikoXx
    @xXEkoLogikoXx 2 роки тому

    Thank you

  • @NagaVenkateshgavini
    @NagaVenkateshgavini Рік тому

    good :)

  •  Рік тому

    Thanks.

  • @JavaMoth
    @JavaMoth 11 місяців тому

    Omg finally was able to shut down that executor from the controller file on app exit

  • @tesseractentertainmentnetw2570
    @tesseractentertainmentnetw2570 2 роки тому +3

    Hello! Hoping for some help, I'm having issues getting an ClassCastException with the Scene2Controller scene2controller = loader.getcontroller(); piece, the only thing i'm doing differently is using a package, could that be effecting how this should work?

    • @CRASH4R
      @CRASH4R 6 місяців тому

      Bro, i watch this video now and i have the same problem. If actuality: "Scene2.fxml" have , u should change

  • @katt2478
    @katt2478 2 роки тому +1

    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 !!

  • @user-ts6nf9st4c
    @user-ts6nf9st4c 2 роки тому +1

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

  • @Verzach3
    @Verzach3 3 роки тому

    UA-cam doesn't notify this video to me :c

  • @augischadiegils.5109
    @augischadiegils.5109 3 роки тому

    Tnx bro

  • @15bigchina
    @15bigchina 3 роки тому +1

    Thanks for sharing this video , it's really helpful. Only one question that my scene1 login button can't link to login action.
    no drop-down available and if I type "login" manually show javafx.fxml.LoadException: No controller specified

    • @valitx8129
      @valitx8129 Рік тому +1

      You need to choose the Controller class from the left bottom section, below the Hierarchy, called Controller. Then you will see the drop-down menu and the variables to link.

  • @KaraSuraDraw1
    @KaraSuraDraw1 2 роки тому +1

    Heey, im not sure if you can respond as quickly as possible, but how do you pass boolean values of Radio Buttons to another controller? I want to do something if a certain Radio Button is clicked.

  • @csubh
    @csubh Рік тому

    for some reason it shows Node cannot be resolved to a type in the main controller class

  • @silvergodanalyser7762
    @silvergodanalyser7762 3 роки тому

    Hey Mate thanks for the vid!
    Can you link your Eclipse theme? I have already a black one, but yours look better and the overlay (HUD) with the projects are also black and not (like now) only the main window with the code.

  • @tttttroll
    @tttttroll 2 роки тому

    But how can you do this with a label and not passing information through a text box?

  • @yassiressaid3140
    @yassiressaid3140 3 роки тому

    can you do a java dao toturial with practical example

  • @berriahzaki7827
    @berriahzaki7827 2 роки тому

    plz help me i have this problem class com.example.demo1.Nouvauxlocataire cannot be cast to class javafx.scene.Parent

  • @berriahzaki7827
    @berriahzaki7827 2 роки тому

    class com.example.demo1.Nouvauxlocataire cannot be cast to class javafx.scene.Parent

  • @user-tq1qr3hg8n
    @user-tq1qr3hg8n 11 місяців тому

    How can I use Javafx to drawing line by using dda algorithm.¿

  • @ahmedmouad344
    @ahmedmouad344 Рік тому

    i dont really know why everyone uses fxml instead of Java it self to build things this is not the only course that does this and i wanna learn java not xml ..:(

  • @Stella_8008
    @Stella_8008 3 роки тому +2

    Does not work for me i get a big error
    Nvm Got it to work :D
    (btw your tutorials are so fun and good to watch thank you!)

    • @ut5671
      @ut5671 2 роки тому

      i got an exception ...whenever i clicked login...i used the same code..can u help me out plz

  • @hananetahrat6820
    @hananetahrat6820 4 місяці тому

    It not work

  • @teamwang4968
    @teamwang4968 Рік тому +1

    I have a question
    lets say i wanna let the user put his first name and his last name
    so I change the scene2Controller to:
    public void displayerName (String username, String theLastName){
    nameLabel.setText("hello:"+username +" "+ theLastName);
    }
    and the scene1Contoller to a:
    theHelloSceneController.displayerName(username , theLastName);
    with of course adding
    String theLastName = userlastName.getText();
    put it doesn't log in and move to the Scene2
    what should i do
    please help

  • @srinicnu5283
    @srinicnu5283 2 роки тому

    i want the src code plz its urgent

  • @aliwissam9672
    @aliwissam9672 3 роки тому

    Do you use discord?

    • @BroCodez
      @BroCodez  3 роки тому +1

      I do for personal use, but I don't have a server set up for this channel

  • @inhtrongthang3367
    @inhtrongthang3367 3 роки тому

    Please kotlin