For me sometimes the addKeyListener or something didn't work and nothing happened when I pressed any buttons. Adding gamePanel.setFocusable(true); before the gamePanel.requestFocus(); in the Game.java helped and it seems to work now. Maybe it's helpful for someone else too.
Man, You are amazing you easily made me learn java in just 2 day obviously not complete but i got the basic understanding of how it works, thank you dude.
This series is extremely helpful and very well produced. The code, the explanation, the editing of the videos. There is just a lot of effort in all of them, and in a very consistent way. Literally cannot phrase how much I appreciate it! You are a legend
I have to say this, this is the clearest explanation I’ve ever seen. Thank you so much, there are a lot of things that I finally knew how and why I do it! I hope this channel keeps growing
@@KaarinGaming can you explain why your gamepanel.changexDelta(-5) doesn’t display a error?? Mine shows that I cannot make a static reference to a NON-static reference
When I tried to make a snake game alone, I got to this part (not 100% similar since I tried to use windowgame as an extension of jframe but it was close) but when I got to the part of trying to move the rectangle it didn't work, the input was not working no matter what I tried, so I hope this tutorial clarifies that. It's been great so far, the first part was very insightful. Generally tutorials just type stuff without explaining, it's great that you take the time to give a brief explanation of what everything does, so good job! Edit: finally I was able to move the rectangle, what happened was I didn't pass GamePanel as parameter for KeyboardInputs and "this" as parameter when calling it in the GamePanel itself in my previews game, now it's making a bit more sense. Definitely an underrated channel.
Good stuff man, other tutorials don't go in detail or explain WHY it is they're doing something. Makes me wonder the point of watching rather than copy-pasting their code. But you actually explain your actions well, appreciate it. The sketches explaining theory is also really nice
I usually never comment, like, or subscribe, but I had to for this free content! I’m currently a student here at Princeton and these tutorials are top notch and eloquently explained. They’re helping me learn so much. Great job.
I made myself move the rectangle with mouse click and drag and i can't express how HAPPY i feet when it worked after half an hour trying it. AMAZING tutorials, you make me want to try stuff by myself because i can understand your explanations so well and really clear. Thank you very much!
I’m having an issue at 1:30 because my IDE (visual studio) doesn’t recognize Key Listener at all. So I can’t do addKeyListener and it’s subsequent things. Please help.
thanks for the tutorials. Ive taken a few intro to programming classes and i think i got the basics down. making games is much more fun than solving word problems.
@@KaarinGaming you explain good I just like need to know things like who is calling paintComponent method in gamepanel? Also the arguments in those methods are unclear, who's sending and who's recieves it. Also how is that the addMouseListener and keylistener and other events connected to the panel? Is it by using those methods (addMouseListener...) that are connecting them?
@@vindirect Lets begin with paintComponent() WE do not call paintcomponent directly ever. When we start the program, and we extend jpanel or have a object of that, it gets called automatically. Its part of the entire java.swing library/ system. (swing have alot of premade classes and method for us to use when we would like to build a interface, a GUI. But we are not building a gui, we are building a game. So we just need jframe and jpanel) So thats how it gets called in the start. But if we would like to make the images and objects move on the screen. We first add or remove values to their positions. Then we need it to be redrawn at the new pos. This is where repaint() comes in. And the purpose of repaint is just that. Tell the jpanel to redraw. And that is how we call paintComponent when we need it to be updated. And repaint is also part of java.swing ( the gui library ). If we used some other ways to draw, say openGL, then repaint and jframe and all that is completely useless. But we are in the java.swing system, so repaint is working. And the graphics object we pass in, is required beforehand. And the graphics object is not created by us, its made further up the chain beyond jpanel. We are given that object to draw with. They give us the paintbrush, now we can use it in this method. The key and mouselisteners are methods we can call. We extend jpanel, and jpanel extends jcomponent and so on. And at one point, there is a method in one of those super classes that have the methods we just called. They require a listener. So we could either create a new one inside the brackets or give it a class that implements the methods. Thats why we create a class that implements the listener, makes it easier to handle the code. We could have add the listeners to jframe , but we will use jpanel (gamePanel) to draw on and the buttons and menus and all that, will be on gamepanel too. So if the inputs were added to jframe, we could not use those buttons. I hope i cleared up some stuff. I talk about this in the first episode. Maybe not quite so in detail.
if u use vs code instead of eclipse remeber to remove the throw new UnsupportedOperationExceptions because i forgot to in the mosueinputs class and oh boy i had a party in that terminal
One thing I want to add to the changeXDelta and changeYDelta function. The reason why changing the value in x axis with -5 moves the rectange upward is because the method fillRect starts making the rectange from (0,0) in the 4th quadrant and moves the positive x axis in the downward direction and the positive y axis in the right direction. so the x axis's normal positive and negative integers change in the opposite order
Hey I just found you channel and the object you create, private MouseInputs mouseInputs, keeps giving me this error "Syntax error on token "MouseInputs", @ expected" I've tried retyping it and looking it up but I got no answers. any ideas?
i love your content but i'm not sure if it's good for beginners i was learning oop now and found your youtube channel. To understand it completly i think i should learn more about oop what do you guys think?
Vid 12:10 får jag ett error. När jag ska försöka importera GamePanel vill den att jag ska skapa en ny klass GamePanel, problemet är att den redan finns ju. jag använder mig av default pack, är det det som ställer till det?
Nvm, jag skapade ett nytt package som heter main och nu kunde jag importera GamePanel, har ingen aning om varför man inte kan använda default package bara aja, it is what it is I guess :)
PLEASE HELP ME! I typed the addKeyListener(new KeyListener); but it doesn't bring the code thingy up where you get the huge amounts of code, instead it says KeyListener cannot be resolved to a type and it's telling me to create a class called KeyListener or other things. I know this is an old video and you probably won't answer but please help i would really like it!
@@KaarinGaming Thank you so much! This really helped :) I'm still a big noob in coding and don't know a lot of stuff, i'm following your tutorials for my first game so thanks!
Hello ! good job for this video , i have a problem , when i use the methode repaint() as you do at 15min and when i test it by moving with zqsd , my rectangle leave trail on my screen how could i resolve this? Thank !
Everything was going fine until I hit one part. For whatever reason that I am unable to find, the "GamePanel" in the KeyBoardInputs does not work!! It shows a red underline and then that's when the problems start to kick in. I tried to change some stuff, but it does not work and when I added "this.gamePanel = gamepanel;", it still shows error! Then when I add "this" inside the "addKeyListener(new KeyBoardInputs(this));" it shows wrong. The "xDelta" and "yDelta" don't with either. I tried what the pinned comment said and it STILL shows error. This is really irritating as I've been trying to find what's wrong for a long time and actually went ahead to redo the entire thing but got stuck on that part again 😭 can anybody tell me what's wrong??
plus u have to do exactly what tutorial says, if u on vs code u need to also install the vs code java extension because it has java intelli so it'll automatically import tit for u
Hello, @@CGRcodeYT! Thank you for your reply. Although it has been a long time since I typed this comment, I even forgot about it. I had tried multiple things and other tutorials but I couldn't find what's wrong, so I just gave up 💀 I have deleted it long ago, and do not remember any terms or anything from Java. Yet again, even though it's been a long time, I still appreciate your response. I may take Java again someday, in which case I'll keep in mind what you said. Have a great day!
when i put gamepanel in the constructor for keyboardinputs it tells me that there is an error and that it cannot find the symbole gamepanel. anyone know why?
at 12:00 i typed the constructor for KeyboardInputs and "private GamePanel gamePanel" and GamePanel just gives out an error or something. i saw a similar comment about this and tried the "import main.GamePanel" trick, but it doesn't recognize it. i don't know if it's because I'm using a different Java version(or JDK, SDK, i don't even know this is still confusing) or it's IntelliJ. i tried IntelliJ's suggestion which is to create a type parameter which basically goes "public class KeyboardInputs implements KeyListener". it solved the error UNTIL i tried to call the changeYDelta method. so, i'm kind of stuck for now lol UPDATE: i figured it out. i had to create a main package and move most of the classes inside that package (hence the "package main;" on top of most classes in this video). i believe this isn't the default behavior in IntelliJ since i do not remember having to create a main package when i was in my CS class like 9 months ago. i don't do programming so idk how different IDE's behave
In the GamePanel.java class you removed the line "import javax.swing.JPanel" that was present in the last episode, but somehow your window is still working? It isn't for me though.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "main.Gamepannel.changeYDelta(int)" because "this.gamepannel" is null why this error is coming how to solve this
Could you explain to me the logic of the movement so maybe it's a silly question but why when we want the rectangle move to up we must subtract pixel (-5), I cant understand that :c Really good video btw
hey bro if u still don't know the error, maybe my comments can help you you should have to call the super.paintComponent(g); and remember paintComponent not paintComponents, i struggle with this error to and when i see in my source code there is typo there
Bro in class keyboardinputs implements keylistener in this click keyboardinputs will get underlined it show unimplement something click that you will Getvthatvinline
Nha, you got this :D Take it slow, and re-watch a few times if you need. Remember, you have a discord to use if need be. Just let me know when you join or what your name is so I can promote in the discord since you are a member =)
Hey @KaarinGaming 12:02 the global variable you added was showing some error in my system but when I imported main.GamePanel, was glad it worked but how did it work I don't know could you clarify it? P.S I am using VS Code Incredible work bro love frm India❤
Hey! I think i already had it imported. Sometimes i re-record what i coded, and then there is a chance of some parts not being removed from one take to the other. So up there i must have had the import already before typing it out. Thanks for the kind words =) Cheers!
guys if addKeyListener didn't work for you, all I did was add a curly bracket so like this. addKeyListener( new KeyListener() { *** all the override methods will be inside here. } );