Java Video Tutorial 21

[ad_1]
Code Here:

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.


Posted

in

by

Tags:

Comments

33 responses to “Java Video Tutorial 21”

  1. RD Avatar

    Thanks, this was a great tutorial

  2. Xydez Avatar

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

  3. Mr Arclight Avatar

    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 🙂

  4. thenewridaraz Avatar

    can we implement action events in another separate class?

  5. Dani Jeney Avatar

    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!

  6. Johnny Batafljeska Avatar

    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

  7. Jacob Dwyer Avatar

    You are the best man!

  8. Xpack Gunners Avatar

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

  9. Genet Asefa Gesese Avatar

    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.

  10. Haya Baig Mirza Avatar

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

  11. MinecraftMovieMaker Avatar

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

  12. Simran Singh Avatar

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

  13. mantelis kmitas Avatar

    then do you need .this and then you dont?

  14. BCwithPC Avatar

    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?

  15. AKSHAT SHARMA Avatar

    hi derek you created a class variable and then you created same variable in a method…..which will get prefrence…..like you created Button1 in both

  16. Prince Gupta Avatar

    You missed mouseMotionListener

  17. Prince Gupta Avatar

    your videos are amazing…

  18. Eugene Kuzmov Avatar

    is JButton a subclass of JPanel?

  19. vishal singh Avatar

    sir derek banas do you publish books . so that we can refer

  20. Ajay N Avatar

    Nice videos..

  21. Abdulnaser Sheikh Avatar

    Hey, the swing Library has been retired by javafx. Can u please do a video on javafx and fxml?

  22. Nicholas Davis Avatar

    Hi Derek (and community),

    Amazing videos, I have made your videos apart of my morning routine and I have recommended them to my students as well.

    Quick Question.
    When I auto implement the ListenForWindow (and other Listener) methods, my version of Eclipse defaults the parameters as (WindowEvent e) instead of (WindowEvent arg0). What your video shows.

    I know its not a big deal, but I would like to know how to change this? I am assuming it is somewhere inside Preferences. (Mac User)

    Thanks Again, keep up the great work.

  23. jerg70 Avatar

    for some reason the method "mouseClicked" ain't working… I tried to append text in the "mouseEntered" method and it worked well when the mouse entered the area… anyone knows what could it be?

  24. Anthony Gittens Avatar

    how do you convert the contents in the textfield to a int?, also how do you insert a function to a button, i 'm doing a project and i need to make three buttons and each one has to do something different when you press it based off of the contents in the text field

  25. Ashved Lochun Avatar

    Hi derek, i would like to know how to navigate from a login window to the menu window after clicking login button. can you help?

  26. Ryan Doherty Avatar

    If you are using IDEA click the light bulb and then Implement methods for the part at 6:30

  27. Marko Zivko Avatar

    GREAT STUFF! 🙂

  28. Keertika Gupta Avatar

    int xPos =(dim.width / 2)-(this.getWidth()/2);
    why this is used in calling getWidth and object is used in calling width

  29. arkae129 Avatar

    Nice job on your video tutorials!
    I got a problem though:
    e.getSource() == button1 won't evaluate to true. Do you know what the problem could be?
    If I remove the flow control everything works fine.
    I'm on Mac OS X 10.11.2
    java version "1.8.0_65"
    Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
    javac 1.8.0_65

  30. Coriiu David Avatar

    6:30
    quickly import – CTRL + SHIFT + o
    quickly add unimplemented methods – CTRL + . and then CTRL + 1 and hit ENTER

    Best tutorials i've followed and also your channel is very interesting

  31. GeoffPlays Avatar

    In the class ListenForKeys, it won't let me append to my TextField, it says the method append(string) is undefined for the type JTextField.

Leave a Reply

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