Java Video Tutorial 21

Java Video Tutorial 21

FavoriteLoadingAdd to favorites

Code Here:

Java468x60

Best Java Book :

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.

source

By |2019-10-09T23:06:34+00:00October 9th, 2019|Java Video Tutorials|33 Comments

33 Comments

  1. VEDANSH SOMANI October 9, 2019 at 11:06 pm - Reply

    Derek, I like your videos but..
    There are plenty of errors.
    I am a student who is trying to learn Swing by your videos but there are many errors you might wanna correct.
    0:40 It's java.awt.event.*; (not events)
    There are a bit more errors I forgot about but please correct your errors as I and many others rely on you for our Java Swing studies…

    Plus I work in BlueJ and couldn't implement the unimplemented methods

  2. Ratul Das October 9, 2019 at 11:06 pm - Reply

    Hello Sir,Getting this kind of error while adding scrollbar in my Frame–
    "Exception in thread "main" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
    at javax.swing.JScrollPane.setVerticalScrollBarPolicy(JScrollPane.java:506)
    at javax.swing.JScrollPane.<init>(JScrollPane.java:296)
    at frame.<init>(Das.java:28)
    at Das.main(Das.java:6)"

  3. Ariton October 9, 2019 at 11:06 pm - Reply

    Hey, can you tell me what is the best method to create listeners in your opinion?

    A) public class in different file

    B) private class like shown in this video

    C) inner anonymous class

  4. Alick Campbell October 9, 2019 at 11:06 pm - Reply

    What line in the code is the frame actually created?

  5. Jaree K October 9, 2019 at 11:06 pm - Reply

    mans have taught me more in a 20 min video than my teacher did in a semester

  6. Shawn Armstrong October 9, 2019 at 11:06 pm - Reply

    Eclipse will run the program; however, the compiler is reporting a lot of errors.

    Multiple markers at this line

    – Access restriction: The type JFrame is not accessible due to restriction on

    required library C:Program FilesJavajre1.8.0_181librt.jar

    – Access restriction: The method setDefaultCloseOperation(int) from the type

    JFrame is not accessible due to restriction on required library C:Program FilesJava

    jre1.8.0_181librt.jar

    – Access restriction: The field EXIT_ON_CLOSE from the type JFrame is not

    accessible due to restriction on required library C:Program FilesJavajre1.8.0_181lib

    rt.jar

    – Occurrence of 'EXIT_ON_CLOSE'

  7. Raphael Nazirullah October 9, 2019 at 11:06 pm - Reply

    Kindly add title of video to you video names to let audience know what the video is about in advance. Needless to say, amazing videos. Thanks a lot.

  8. Nihal M October 9, 2019 at 11:06 pm - Reply

    Hi Derek, thanks a lot for all your videos! They save my skin most of the time, else I'd have to break my head for all these things. Thanks a lot!

  9. Yanis Onjulis October 9, 2019 at 11:06 pm - Reply

    Hi Derek, you have very good videos and teaching skills =))
    I didn't saw yet all your videos, but I have project to do and I need use java swing without "ActionListener" and "ActionEvent". If you can help or some one who are reading this post can help me, I will glad to you guys =))

  10. ronith. NR October 9, 2019 at 11:06 pm - Reply

    Hey Derek love you for your amazing teaching skills. I just started few days ago and your tutorials are very engaging and im loving it. I have few questions you mentioned class variables like button1, textField1, textArea1 since these are class variables you have to mention static so that it should be accessible by all the other methods right? please do clarify that im getting confused in this part.

  11. FervidGames October 9, 2019 at 11:06 pm - Reply

    Thanks. Didn't work cus I have everything in one Main Class. but I get the concept

  12. fedvgo October 9, 2019 at 11:06 pm - Reply

    best videos every thank you

  13. Lightning theBeast October 9, 2019 at 11:06 pm - Reply

    Derek i am trying to make a code where is i press a button , some text will be appended to a text area but I cannot make it work .
    I rewatched your videos 10 times yet i am unable to find out the problem , help would be highly appreciated πŸ˜€

  14. Patrascu Lucian October 9, 2019 at 11:06 pm - Reply

    – Great tutorial
    – Simple explantion

  15. Ahsan Hanif October 9, 2019 at 11:06 pm - Reply

    such a great and greenery videos amazing absolutely!you rock……..!

  16. Clay Stamper October 9, 2019 at 11:06 pm - Reply

    it wont let me reference the non-static button1 variable and the global variables are saying "can't be resolved to a variable" in the listener class. Also won't let me make the class private. Any help?

  17. CRAZYFLYINGPOOP October 9, 2019 at 11:06 pm - Reply

    Really helpful thanks! love the pace you explain at and the fact that you broke it up into clearly defined sections with the animations!

  18. RD October 9, 2019 at 11:06 pm - Reply

    Thanks, this was a great tutorial

  19. Xydez October 9, 2019 at 11:06 pm - Reply

    They removed "java.awt.events.*"
    Did they replace it with "java.awt.Event.*"?

  20. Mr Arclight October 9, 2019 at 11:06 pm - Reply

    Should I learn about swing when its abandoned? I have read that JavaFX is better.
    I can't decide, will learning swing from these tutorials (~20th – 30th lesson) help me to understand JavaFX later?
    I just don't know if I should skip it or not, please help πŸ™‚

  21. Nathan Lodge October 9, 2019 at 11:06 pm - Reply
  22. Raz Mhz October 9, 2019 at 11:06 pm - Reply

    can we implement action events in another separate class?

  23. Dani Jeney October 9, 2019 at 11:06 pm - Reply

    Hey! i get this thing, tho no errors shown in eclipse, the window opens tho and text is in there ::::
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at DerekBanasVidsTuts.JavaLessonTwenty$ListenForWindow.windowActivated(JavaLessonTwenty.java:106)
    at java.awt.Window.processWindowEvent(Unknown Source)
    at javax.swing.JFrame.processWindowEvent(Unknown Source)
    at java.awt.Window.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)

    and like 25 more of these.. any idea? thanks!

  24. Johnny Batafljeska October 9, 2019 at 11:06 pm - Reply

    Hello, love your videos, but can someone help me with this..

    private class ListenForButton implements ActionListener{

    public void actionPreformed(ActionEvent e){
    if(e.getSource() == button1){
    buttonClicked++;

    textArea1.append("Button clicked :" + buttonClicked);
    }
    }
    Im constantly getting an error, and when I run the code I get this

    Exception in thread "main" java.lang.IllegalArgumentException: invalid verticalScrollBarPolicy
    at javax.swing.JScrollPane.setVerticalScrollBarPolicy(JScrollPane.java:506)
    at javax.swing.JScrollPane.<init>(JScrollPane.java:296)
    at JavaLesson21.<init>(JavaLesson21.java:54)
    at JavaLesson21.main(JavaLesson21.java:17)

    Of course Im runing your code

  25. Jacob Dwyer October 9, 2019 at 11:06 pm - Reply

    You are the best man!

  26. Kornelije Kovac October 9, 2019 at 11:06 pm - Reply

    2:40 Go there.

  27. Xpack Gunners October 9, 2019 at 11:06 pm - Reply

    how can you memorize all these class names they are kinda overwhelming at first glance

  28. Genet Asefa Gesese October 9, 2019 at 11:06 pm - Reply

    How can I create a hint list for a JTextField? i.e. a list of texts that appear while you are typing in the text field.

  29. Haya Baig Mirza October 9, 2019 at 11:06 pm - Reply

    How do we change the position of our buttons in the exact same code? Help needed.

  30. MinecraftMovieMaker October 9, 2019 at 11:06 pm - Reply

    "The import java.awt.events cannot be resolved"
    Please help.

  31. Sehej Singh October 9, 2019 at 11:06 pm - Reply

    is the Frame style different in mac and windows? coz am using windows and i see less good looking Frame and components on panel.

  32. mantelis kmitas October 9, 2019 at 11:06 pm - Reply

    then do you need .this and then you dont?

  33. Bad Content October 9, 2019 at 11:06 pm - Reply

    So with the part where you got the xPos and yPos of wherever the mouse was clicked inside of the frame. Is that how you would do aiming in a game? Finding the position of a click and seeing if it lines up with a preset of coordinates and if it does then have something happen?

Leave A Comment

*