How To Detect Arrow Keys In Java #98

Поделиться
HTML-код
  • Опубликовано: 6 янв 2025

Комментарии • 97

  • @alexlorenlee
    @alexlorenlee  Год назад +1

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @abhimanyu-kapoor
    @abhimanyu-kapoor 3 года назад +21

    16:41 The count didn't increase on the first click as you used post-increment (upCount++) this will first setText then it will increment. So, it is technically giving the count as one less.
    Instead you could try (++upCount) this changes the value on the first click since its pre-increment.

  • @jscorpio1987
    @jscorpio1987 4 года назад +4

    You deserve a million subs! Your tutorials are extremely useful and easy to understand. And you seem to be such a humble, passionate and sweet guy. Love your videos and I’m so glad I found your channel! Every time I watch one of your videos, I get excited about all the cool things that can be done with programming! It’s my dream to make my own game and your tutorials help me get closer to that goal.

  • @augustoliver351
    @augustoliver351 5 лет назад +17

    Great video. Thank you. I personally would love to see more GUI stuff.

  • @richardknipe2733
    @richardknipe2733 3 года назад

    Really helped me a lot thanks! For those who did not know, the labels only updated after the second press because he used post-incrementing instead of pre-incrementing to increase the respective count variables.

  • @im_jope
    @im_jope 4 года назад +3

    Using a Pre-Increment fixes the problem of needing to double tap.
    Great video!

  • @codershaven1264
    @codershaven1264 3 года назад +5

    Hi Alex!
    You dont have to use the labelName.setText() method to set the text of the label.
    instead you can already specify the text when you initialize the Label variable.
    example:
    JLabel label = new JLabel("Random text here");
    but if you want to set the text to something else later on in the code,
    then setText() can be used

  • @virajchoubey7755
    @virajchoubey7755 2 года назад

    You made Java a fun roller coaster! Loving the way...

  • @JULianMrMP
    @JULianMrMP 3 года назад

    I found this video very helpful up against my university studies project. Clear and fast explaination, thanks a lot!

  • @timthndr2996
    @timthndr2996 2 года назад

    Thank you for this video. Was a great introduction to GUI and keylogging. No idea if you still read this but I will be sure to work through the playlist.

  • @lessongustav5311
    @lessongustav5311 3 года назад

    At least this video helped me more than 3 hours of teaching lessons by my computerscience prof, Great Job !!

  • @luckytramp8120
    @luckytramp8120 5 лет назад +28

    Hi,Alex! "VK" is meant "Virtual Keyboard"))

    • @alexlorenlee
      @alexlorenlee  5 лет назад +4

      Lucky Tramp ah I didn’t know that, thanks!

    • @陈瀚龙
      @陈瀚龙 4 года назад +1

      @@alexlorenlee I'm still with you, Alex. I think it stands for "something".:) You're funny, little brother. Great videos. Thanks. keep it up.

    • @sivapradeep977
      @sivapradeep977 4 года назад +1

      Hey I'm from India...and VK means VIRAT KOHLI 👑 lol..

    • @deadpl55
      @deadpl55 3 года назад

      @@vaibhavparate2131 yeah i knew it from c++

  • @ANerdyCoder
    @ANerdyCoder 2 года назад +1

    Thank you so much your explain everything so well

  • @Daniel-iy1ed
    @Daniel-iy1ed 2 года назад +1

    Thanks mate. You are amazing , I really enjoy watching your tutorials and learnt a lot

  • @ramirezcameron
    @ramirezcameron 5 лет назад +1

    that's a pretty unique way of doing it. I can plop that down anywhere in my code instead of finding some way to communicate between methods. Thanks!

  • @yaminivaka9748
    @yaminivaka9748 2 года назад

    Great content... Pls do more of such practice videos , these are so helpful for beginners who learnt basics and trying to get hands-on with java programs😇

  • @zarkmuckerberg8341
    @zarkmuckerberg8341 3 года назад +1

    At around 15:23, why do you convert the integer to string?

  • @MannatTrivedi
    @MannatTrivedi 5 лет назад +17

    Hi I am a 15 year coder because of you.
    I have a code:
    System.out. printIn("Alex you are amazing");
    System.out. printIn("Love from India");
    Output:
    Best teacher ever.

    • @alexlorenlee
      @alexlorenlee  5 лет назад +2

      haha awesome, I'm glad you like my videos!

    • @entropy3387
      @entropy3387 4 года назад +1

      I doubt you'll get that output from that code.

  • @flwer1
    @flwer1 4 года назад

    AMAZING! my first time coding a program with GUI and i just love it ♥

  • @uzmanackvi7411
    @uzmanackvi7411 4 года назад

    So far my favorite video on your channel! Hopefully you will unleash the power of Java for GUIs, fingers crossed!

  • @shauryagaur1262
    @shauryagaur1262 5 лет назад +10

    Hi Alex I am your biggest fan from India :)

    • @alexlorenlee
      @alexlorenlee  5 лет назад +2

      Fun time with Parth and shaurya woah that’s awesome! All the way out from India, welcome!

  • @marko8640
    @marko8640 4 года назад

    Absolutely brilliant video. Sorry to see you left Java teaching, but subscribers are still coming, as I can see. If you change your mind someday, please consider more GUI content on this channel. Cheers!

  • @irioxirioxis9532
    @irioxirioxis9532 2 года назад

    underrated Channel thanks for your content !

  • @jefersonferreira7821
    @jefersonferreira7821 5 лет назад +1

    Awesome dude, that's kind of makes it easier the way you teach

  • @dananca8539
    @dananca8539 4 года назад

    Heyy thanks a lot for the efforts you ve been putting in your channel! It s the first app I made and Im really happy. Even exported it and made it as an actual app to see if it d work, and it does! Also, just put ++upCount etc so it'll start with 1 from the first click

  • @jonathanphillips5915
    @jonathanphillips5915 4 года назад

    I laughed so hard at the "VK" part haha, Thanks a bunch bro, I seriously appreciate you and the videos!

  • @janjindrak3448
    @janjindrak3448 4 года назад

    Thank you, I had a problem with this and I couldn't find a solution for several days, until now.

  • @howyoutubesmells
    @howyoutubesmells 8 месяцев назад

    Thanks, really usefull when showing to newphew how to work with key press events.

  • @hanzhe5529
    @hanzhe5529 4 года назад +2

    Hi, I have a question here that is why do we need set.Focusable(true) and what it is? What happens if we do not have it in the program?

    • @agnibinasaha7047
      @agnibinasaha7047 4 года назад +1

      I am also confused for what the set Focusable and set default close operation does because by writing or deleting them make no change in the JFrame window

    • @hanzhe5529
      @hanzhe5529 4 года назад +4

      @@agnibinasaha7047
      From what I understand from the other forums is that:
      By using the set default close operation, when you close the the jframe window the program will be terminated and stop running completely. (If you. use .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) )
      If you don't use the set default close operation, the java program will still run in the background even after you click the close window.

    • @agnibinasaha7047
      @agnibinasaha7047 4 года назад

      Thank you very much . I have another problem , how can I print multiple lines in JFrame , please help me .

  • @mysilviase3968
    @mysilviase3968 3 года назад

    hello Alex....im really strugggling with the Java like when i create the package or class or when to pull something from the other class or package

  • @ednaldopereira2646
    @ednaldopereira2646 4 года назад +2

    THANK YOU SO MUCH, BRUH I HAVE TRIED THAT TOO MUCH, ALL LONG DAY, JUST FOR THAT THING

  • @adibaqil9191
    @adibaqil9191 5 лет назад +1

    My coding said that cant find symbol for keyevent
    Second is says method does not overide (@Overrride)
    And lastly at frame addkeylistener(new keylistener) is said that it is not abstract and not overide. Plis help me someone

  • @kirankumarmothukuri7660
    @kirankumarmothukuri7660 4 года назад

    Thanks Alex. keep rocking, you will get lots of subscribers. Could you also focus on stream api's?

  • @MannatTrivedi
    @MannatTrivedi 5 лет назад +4

    Big bro Alex, I am unable to subscribe your mailing list....

    • @alexlorenlee
      @alexlorenlee  5 лет назад +2

      are you on mobile? My website is a little finicky on mobile and might not let you enter an email, but it should work on your computer

    • @MannatTrivedi
      @MannatTrivedi 5 лет назад

      @@alexlorenlee Thank you..

  • @SpaceByte
    @SpaceByte 4 года назад +1

    KeyPressed Event doesn't get called no matter what I do, I've triple checked I did EXACTLY as he did, it isn't being called

  • @lukasjetu9776
    @lukasjetu9776 3 года назад

    little help: when you don't have any ide... just create a java file ([name].java) and then code something into it. when you are done coding, save it and open cmd (command prompt) and go to the location where your file is saved and type the following: "javac [name].java" and to start it type "java [name]"... everytime you made a change into the program, do the same process again

  • @Popa4Gaming
    @Popa4Gaming 5 лет назад

    ok I guess your tuts will help me a lot with my school :) thanksss

  • @rustyalminar7229
    @rustyalminar7229 4 года назад

    How to detect fn key pressed event in java
    ?

  • @vipin2356
    @vipin2356 4 года назад

    is not abstract and does not override abstract method keyreleased(key event) in keyListener
    ....
    Sir what does its mean....plz explain me

  • @helsihe1600
    @helsihe1600 4 года назад

    please tell me anyone
    everything he mentioned above this video, do I have to memorize whole thing to type when i need?

  • @aysesahin9133
    @aysesahin9133 4 года назад

    Is it possible to write this code with enigma without using jframe

  • @MinecraftStonewideos
    @MinecraftStonewideos 4 года назад +2

    More GUI, please!

  • @justinspanos4382
    @justinspanos4382 4 года назад

    I love the video. Your content is so awesome. Personally, I would love a buttons tutorial that you talked about around 6:26

  • @jannatmansour7366
    @jannatmansour7366 3 года назад

    Great video. Thank you.

  • @aljoschakainz3365
    @aljoschakainz3365 5 лет назад +4

    the reason u had to type twiche before it startet was that up: 0 and when u type the up key it gets set to: int upCOunt = 0;

    • @salomepereira9929
      @salomepereira9929 3 года назад

      I solved this by doing:
      int upCount = 1;
      int downCount = 1;
      int leftCount = 1;
      int rightCount = 1;

  • @abscodes9587
    @abscodes9587 3 года назад

    @AlexLee please can you do another video to do something with this code and make a simple game

  • @helsihe1600
    @helsihe1600 4 года назад

    Hey, guys one question
    During mimicking his code, and watching this video, do I have to memorize everything? that's the one of the way i can take a one step?
    tho I've been studying JAVA by watching his video, I actually still don't know how to study effectively.
    Im just watching and trying like his code.

  • @FlintNinja
    @FlintNinja 5 лет назад

    Will this work on dr.java aswell?

  • @RizaHariati
    @RizaHariati 4 года назад

    Alex. You're a great teacher. You can make my 44 years old ass understand this stuff... :D

  • @joemarcus6583
    @joemarcus6583 4 года назад

    alex i didnt understand the keylistener part please i would appreciate it if you made its more clear in another video.i love your channel and i always watch your videos.thx : )

  • @agnibinasaha7047
    @agnibinasaha7047 4 года назад

    Thank you I got the solution and my programme is running perfectly but I have another question , how can I print multiple lines in JFrame ? Please help me .

    • @arturmartincovschi9901
      @arturmartincovschi9901 4 года назад +1

      You can do that by setting the layout of the panel to "null" and then set the bounds of the other Labels

  • @damanlamail
    @damanlamail 4 года назад

    Hi Alex, can you please make some videos on UI app development

  • @firazmarzin9778
    @firazmarzin9778 4 года назад +1

    Hi, can i know is it possible to get the key press count as you did without the focus of the relavant window? If yes any help here!!

  • @agnibinasaha7047
    @agnibinasaha7047 4 года назад

    My programme is showing an error ' cannot find symbol class KeyEvent ' please help me to fix it . By the way I am a big fan of yours from India

  • @medicoz23
    @medicoz23 2 года назад

    I ve created this . But arrow keys are not working . My lappy is Lenovo IdeaPad slim 3
    Also I would like to send a screen shot how can I send u .

  • @mastergamer4335
    @mastergamer4335 3 года назад

    cant you make a video on how to make java click a arrow button?

    • @mastergamer4335
      @mastergamer4335 3 года назад

      like when i click k it triggers a function that clicks d.

  • @shotx333
    @shotx333 3 года назад

    You can save some lines with regex but thanks for the video anyway

  • @ratnamukhopadhyay9733
    @ratnamukhopadhyay9733 4 года назад

    You should use pre increment operator instead of post increment operator

    • @maelstrom57
      @maelstrom57 3 года назад +1

      for those of use who only speak English: that means use ++upCount instead of upCount++

  • @elijahmock
    @elijahmock 4 года назад

    Nice keyboard

  • @drillspotter9023
    @drillspotter9023 2 года назад

    you should've have put ++upCount instead of upCount++, or set the upCount starting value at 1.

  • @Just_Chuk
    @Just_Chuk 4 года назад

    one word.... gooey

  • @imiramikhanirami3624
    @imiramikhanirami3624 3 года назад +1

    You sound like J Perm!

    • @ven4zra
      @ven4zra 3 года назад

      thats what i thought

  • @Kamal-vd1zg
    @Kamal-vd1zg 5 лет назад

    Hi Alex please make more videos in Java fx please thanks
    System.out.print(“LOVE FROM AFGHANISTAN “)

  • @Svtslav-v6q
    @Svtslav-v6q 5 лет назад

    first press had no effect because you wrote directionCount++ instead ++directionCount

    • @mattvella
      @mattvella 5 лет назад

      They mean the same thing in Java, they both work

    • @im_jope
      @im_jope 4 года назад +1

      @@mattvella They don't, one is a Pre_increment and the other one is a Post-increment. While they both increase the value by one, they do it at different times.

  • @florriemccarthy9347
    @florriemccarthy9347 4 года назад

    I hope people are still here reading these comments, because I don't know where else on the internet I'll find this specific problem...when I press one of my arrow keys all the numbers go up? Some of the keys only increase their own number, some increase two, some increase all...depends which I press first every time I run it. This might be useless, to ask it here, but if someone had an answer that would be amazing!

    • @shen968
      @shen968 4 года назад +1

      Have you checked the variables name for counting? Maybe you have duplicate name for counting variables in different keys.

  • @nostalgia5031
    @nostalgia5031 4 года назад

    What is that keyboard -.-

  • @shokokimera7358
    @shokokimera7358 2 года назад

    Hi there, has anyone ever told you that you kinda sorta look like Rosamund Pike?