In 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
wowww, just waiting for your new video, will watch it today…
thank you….
You’re very welcome. It’s a tutorial packed with information
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.
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..
Your in luck. I’ve already covered that topic using PHP. Every technique is nearly identical using Java
PHP Security
PHP Security Pt 2
PHP Security Pt 3
PHP Security Pt 4 Set Up Captcha
PHP Security Pt 5 SQL Injection
PHP Security Pt 6 Directory Traversal
Web Design and Programming Pt 21 Secure Login Script
Well my good luck works for me..;-)
but the functions you are using are for php, how do i use them in java??
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
okay…thanks…
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.
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?
hi derek, thanks for the video man, i just had one question.
=>what is the difference between keyPressed and Keytyped method.
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
hi derek, can u tell me what is the difference between keytyped and keypressed
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
Hey Derek, what is a FocusListener meant to do?
Sorry, I wasn’t patient enough. I understand it now :).
Sorry I couldn’t get to you quicker, but I’m glad you understand now 🙂
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.
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.
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
Sure feel free to bounce around in the tutorial however you’d like.
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
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
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!
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 🙂
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.
Hi Wang, Thank you very much for taking the time to tell me that I’ve helped. I greatly appreciate that! I wish you and your friends all of the best 🙂
Hi Derek!
Still havent’s figured out what FocusListened does… Could you please give some expanation?
Thanks
A focus listener is triggered anytime a component is targeted by mouse, the keyboard, or programmatically