JavaFX Event Handling using Scene Builder 🎪

Поділитися
Вставка
  • Опубліковано 21 сер 2024

КОМЕНТАРІ • 94

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

    package application;

    import javafx.application.Application;
    import javafx.fxml.FXMLLoader;
    import javafx.stage.Stage;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    //-----------------------Main.java-----------------------
    public class Main extends Application {

    @Override
    public void start(Stage stage) {
    try {
    Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
    } catch(Exception e) {
    e.printStackTrace();
    }
    }
    public static void main(String[] args) {
    launch(args);
    }
    }
    //-----------------------Main.fxml-----------------------







    //-----------------------Controller.java-----------------------
    package application;
    import javafx.event.ActionEvent;
    import javafx.fxml.FXML;
    import javafx.scene.shape.Circle;
    public class Controller {
    @FXML
    private Circle myCircle;
    private double x;
    private double y;

    public void up(ActionEvent e) {
    //System.out.println("UP");
    myCircle.setCenterY(y-=10);
    }
    public void down(ActionEvent e) {
    //System.out.println("DOWN");
    myCircle.setCenterY(y+=10);
    }
    public void left(ActionEvent e) {
    //System.out.println("LEFT");
    myCircle.setCenterX(x-=10);
    }
    public void right(ActionEvent e) {
    //System.out.println("RIGHT");
    myCircle.setCenterX(x+=10);
    }

    }

  • @stas4112
    @stas4112 2 роки тому +28

    If anyone is confused why there is no drop down for application.Controller at 3:44 , it helped to drag the Main.fxml file into the application folder like he did in the previous video. That makes everything work again
    and as always, thanks bro ;)

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

      tnx very helpful. Did not notice your comment first, almost wasted half day googling

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

      my fxml file is in my class folder tho. there's no drop down.

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

      @@cornmasterliao7080 same

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

      yes it happened to me as well, i just put the Main.fxml file inside the src Folder, and changed the code to: "getResource("Main.fxml"));" and i got the drop down lists working

  • @dablo898
    @dablo898 2 роки тому +9

    I have paid for the courses, But your tutorials beat them all in Quality and delivery. Thanks Bro.

  • @michaelk.6966
    @michaelk.6966 2 роки тому +1

    Один из лучших видеокурсов по JavaFX

  • @thedev5126
    @thedev5126 3 роки тому +6

    If anyone gets a ton of errors at 7:10 (or just when you write "@FXML" ) I found a solution. It might mean that you need to export some sort of package that program can't locate or whatever. The general solution to this is:
    opens to javafx.fxml; (in your case is probably "application")
    you just have to manually write that code into your fxml file so it looks like this:
    module SceneBuilderEventHandling {
    requires javafx.graphics;
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.base;
    opens application to javafx.fxml;
    exports application;
    }

  • @abelxotessema343
    @abelxotessema343 6 місяців тому +2

    The Controllers drop-down is missing on my IntelliJ. So, what I did was, I selected the Text tab at the bottom of the FXML file (there are Text and Scene Builder tabs), went to the opening AnchorPane tag, and modified the fx:controller attribute to the controller I set up (in my case, I made it: fx:controller="com.example.demo.E06EventHandlingUsingSceneBuilderController"). And it worked. And the methods showed up in the drop-downs in the Code drop-down on the right panel of the buttons in the Scene Builder tab.

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

    i have done it. Thanks. I from Russia and I like your videos about JAVA

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

    I just clicked the ad to support you... 😍🙏

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

    Excellent tutorials. Bro is a good teacher💪

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

    Thank you so much, your explanation is so clear

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

    Only You helps me
    (Better Than my Teacher)

  • @user-dl8iv7mb7n
    @user-dl8iv7mb7n 6 місяців тому

    I like your videos. You are the best BRO

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

    da best

  • @sam-williams1
    @sam-williams1 2 роки тому +1

    Thank you. You made this easy to understand.

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

    Super Video

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

    I learn php first then go to java, i felt java way more structured than php.

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

    Nice Video bro ...

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

    Super explanation 😃

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

    Good

  • @kole1678
    @kole1678 2 роки тому +9

    I'm confused on how the x and y are connected to the circle? like ok we hook the circle in scene builder with the myCircle instance, however then we add two doubles which we never initialize and then we tell the methods to use this value for setting the position of the circle, how does the program know what we mean to do?

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

      in the middle of the screen is the point (0,0)

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

      @@aohoang3215 to me that is a hidden side effect which is undesirable in a tutorial. Someone might try and use this code in a slightly different setup and not understand why it is not working.

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

      I had been wondering the same thing. Watched through the video several times trying to see what I was missing.

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

      @@jamesschmames6416 @kole1678 It's been 2 years now, do you remember the reason??? I'm stuck at the same place!

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

    Useful 👌👍

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

    Thumb up, great work!!! ... as usual 😉

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

    Thanks a lot for your efforts, It helps a lot

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

    I learn a lot .tnx

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

    Great Video!

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

    Im from Java tutorial just to see if you're still uploading, keep it up!

  • @MVL-be5eo
    @MVL-be5eo 10 місяців тому

    Thank you very much! 👍

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

    great videos!

  • @retr0k964
    @retr0k964 3 роки тому +6

    After coming from your Java swing tutorials, this SceneBuilder stuff feels like cheating? Am I cheating?

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

      No

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

      You know, I thought the same thing about someone using NetBeans (if memory serves) for Java Swing). After mulling it over, I came to the conclusion that, while it feels pretty good to type a bunch of code and watch it run, things like NetBeans and SceneBuilder is more efficient. And that means you can get more stuff done. It's like this: Sure I can ride a bicycle 2 miles to the grocery store, but a car is faster and can haul more groceries. Is using a car cheating? Maybe. Maybe not. As long as the job gets done and works as intended, I'm happy.

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

    Great video, thanks!

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

    Great video!

  • @HaHoang-ly9hw
    @HaHoang-ly9hw 2 роки тому

    niceeeeeeeee

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

    Dude, i'm in love with these emojis hahaha ♥♥

  • @khaledeldingawy9234
    @khaledeldingawy9234 5 місяців тому

    thanks bro

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

    Bro,you are legend :D

  • @jofafs
    @jofafs 7 місяців тому

    thanks bro!

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

    Awesome!!!! Thanks!!!!!!! :)

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

    Actually, Bro I have started learning java rather than stuffing my mind with alot of languages. I don't know yet its end point. I want bro you to help me to learn java well. I will be very thankful to you in my entire life.

  • @pratyushgangwar9747
    @pratyushgangwar9747 25 днів тому

    thanks!

  • @skorpion9236
    @skorpion9236 3 роки тому +5

    Thanks so much for these useful videos! I hope you won't drop this series, your videos helped me a lot in Java as a beginner.
    + 1 like and subscribe

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

    Thanks bro helped a lot

  • @chocodonuts3644
    @chocodonuts3644 9 місяців тому

    Thank you so much

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

    gg

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

    Thank you.

  • @Lucas-iv6ld
    @Lucas-iv6ld 9 місяців тому

    Thanks

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

    thank you bro

  • @abelxotessema343
    @abelxotessema343 6 місяців тому +1

    I have a question. Aren't x and y initialized to 0? That is, when we press, say, up, the first time, shouldn't the y-value of the center of the circle actually be -10, thus moving it to (0, -10)?

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

    thank you

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

    Sir,please upload game devlopment course

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

    subscribed!

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

    Hi bro, hope you are fine. Bro, I wish if you make a instagram ID. Just will be need your less time. There are some questions and small helps that we need. You already doing great. And I really learning from you. Can you suggest any book for java.

  • @glenn8762
    @glenn8762 10 місяців тому +1

    Not sure if I missed it or I don't understand but how come you don't need to set the initial values for x and y equal to the current x and y of the circle? I was expecting the circle to pop to the left upper corner because the x and y are initially 0

    • @rectaalborween8471
      @rectaalborween8471 5 місяців тому

      If youve figured this out i'd like to know too :(

    • @rectaalborween8471
      @rectaalborween8471 5 місяців тому +1

      on 2nd thought, i think i got it..
      If you set Y to -100 or 100 then you notice initial jumps in the circle.
      This must mean that its X and Y values don't depend on its parent container (IE, y = 200 doesnt mean 200 pixels below the anchor panel, it means 200 pixels below where the circle is initially placed. And since sceneBuilder takes care of the initial values .setCenterY(); only takes effect after we hit buttons )

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

    So does the scene builder replace the event handler method with the one we provide?

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

    From Where you learned programing ?

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

    my circle is null '-'

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

    Привет, тебе!

  • @Zero-ed1ji
    @Zero-ed1ji Рік тому

    Hey bro, thanks for the great lesson, but mine has a little error it goes to Java Lang error

  • @Hselit06
    @Hselit06 16 днів тому

    What is the difference between using swing and javafx

  • @Magnezone962
    @Magnezone962 28 днів тому

    Got this error: javafx.fxml.LoadException: Error resolving onAction='#up', either the event handler is not in the Namespace or there is an error in the script.

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

    Error: JavaFX runtime components are missing, and are required to run this application how to solve please help IntelliJ

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

    merci pour la vidéo mais penser a faire la traduction en Français pas au niveau sous titre puisque j'ai eu un peu du mal a suivre la vidéo mais c'était cas mm intéressant pour moi

  • @freedom-jt8ot
    @freedom-jt8ot Рік тому +1

    how can do it without using sceneBuilder?

  • @chrs-wltrs
    @chrs-wltrs 2 роки тому

    So how does this work if you need to access methods that use 'stage,' since `primaryStage` is in your main class, not your controller class?

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

    Hey, why to up the circle I use "y -= 10"? In Cartesian plane the y-axis "up" are the positive values, not negatives. What logical JavaFX uses?

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

      Like most GUIs, JavaFX thinks that the origin - the point (0,0) - is the top left and everything is measured from there. As there is little use for points above the top of the window or to the left of the left side of the window, the x-axis uses units of pixels going to the right from the origin and the y-axis uses units of pixels going down from the origin.

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

    what should i learn swing or javafx?

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

      It could be argued that both are outdated but javafx is less outdated than swing. You are going to get a lot more with less work in javafx, but it more complex in some ways so when things don't go as planned it may be harder to figure out why.

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

    How about using Social Media?

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

    Can I print a variable as a label in SceneBuilder?

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

    bump

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

    Is JavaFX better easier than Java?

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

    I don't know if any else, whose using Linux, has this problem or not, but SceneBuilder is laggy as hell if used through eclipse. However, if I open it outside of eclipse, it runs smooth as butter. If anyone knows why this is, or how to fix it, then please let me know.

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

      no i am using mx linux it works smooth, but facing issue that scene builder is not showing controller class in dropdown

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

    Hi,
    my code is the same that yours and it's not. working like The Dev says down there but is fix don't work with me.
    Can you please share for each video the code that works ?
    Tks Bro 🙂
    My error :
    Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.shape.Circle.setCenterY(double)" because "this.myCircle" is null

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

      I found it : my id name was not the same that the variable name grrr !!!

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

    hey bro, could you make a video on making a mvc project? with interface, abstract class and all of that. Really struggling with it and there's no good explanation on it on youtube

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

    Good