Java Video Tutorial 21

Java Swing Event HandlingIn this part of my Java Video Tutorial, I will cover GUI Event Handling. If you missed my Java Swing video tutorial, watch that first.

Here I show you how to implement the ActionListener, KeyListener, MouseListener and WindowListener. I also show you some easy ways to use interfaces so that you don’t have to memorize all of the required methods for each interface.

All of the code follows the video. Definitely look at it so that you will find it easier to learn.

If you like videos like this share it [nttfblike]

Code from the Video

29 thoughts on “Java Video Tutorial 21”

  1. if possible add some security concerns for web development in java(ie. how to secure from sql injuctions, cross site scripting, how to set up https in tomcat) etc, to make a website secure, like an e-commerce site.

  2. if possible please, do some tutorial for java securities in web devlopement(ie. how to secure site from sql injuctions, cross site scripting, how to setup https in tomcat)etc. like useful for some e-commerce sites..

      1. Well my good luck works for me..;-)
        but the functions you are using are for php, how do i use them in java??

        1. Most of what I do is test data using regular expressions. It should be easy to just use those same codes since regex are identical. I’ll cover sessions, cookies, databases as soon as possible. It’s getting harder to cover the more complicated topics quickly

  3. hi derek i have few questions regarding this tutorial
    1.)when we create an object like ListenForButton lForButton then why do we have to pass it like button1.addActionListner(lForButton);
    2.)why do we create private class abc implements def, can’t we do it by defining a function.plz explain. also tell me if a class is defined into another class does it gets all of the fields and methods of the parent class under which it is enclosed.

    1. button1.addActionListener(lForButton); says that when an event is triggered on button1 that you want the class ListenForButton to be called. Then the method actionPerformed is called and it handles what to do when an event is triggered.

      If a class extends another class yes the new class gets all of the methods of the super class.

      Does that help?

  4. hi derek, thanks for the video man, i just had one question.

    =>what is the difference between keyPressed and Keytyped method.

    1. keyPressed – when the key goes down
      keyReleased – when the key comes up
      keyTyped – when the unicode character represented by this key is sent by the keyboard to system input

    1. keyPressed – when the key goes down
      keyReleased – when the key comes up
      keyTyped – when the unicode character represented by this key is sent by the keyboard to system input

  5. Hey Derek,

    Awesome Videos, even though i have a couple of problems with this episode and especially with actionlisteners:

    I am using Netbeans, and even if i copy and paste your code, it gives me a lot of warnings and errors. If i write my own program, which is slightly different from yours, i end up getting errors when i try to implement “private class ListenForButton implements ActionListener{}” for instance. It says it is not abstract and cant override some other method.

    1. That is odd. I also had some weird errors when I used NetBeans in the past and that is why I stuck with Eclipse. I’m using regular old Java in these tutorials so they should work on every IDE.

      Don’t worry about understanding Action Listeners at this point. I cover them a countless number of times over the course of this tutorial. You’ll understand them with a few more examples.

  6. Hi derek nice tutorials.One question, can i skip the swing tutorials, because later i will learn javafx and i want to continue with the thrid part of the tutorials. Can i continue without the swing tutorials.
    Thx

  7. Hi Derek,

    In video you put the code in KeyPressed function but in the code here it is given in KeyTyped method. Moreover, I am a bit unclear between the usage of KeyTyped and KeyPressed.

    Thanks
    Kuldeep

    1. Hi Kuldeep,

      keyPressed – when the key goes down
      keyReleased – when the key comes up
      keyTyped – when the unicode character represented by this key is sent by the keyboard to system input

      1. I have implemented the focus listener and have found may uses for it :), although many, in my mind anyway are web related. Also Happy New Year! Love your videos and keep up the high quality content you produce!

        1. I will definitely be covering how to connect Android apps to remote servers very soon. I’m very happy that you enjoy the videos. Many more are coming 🙂

  8. Hi, Derek. I have to thank you for your work to help the programmers around the world. I’m from China and I have recommended my friends to watch your videos if they want to study how to program. Thank you so much.

Leave a Reply

Your email address will not be published. Required fields are marked *