Java Swing Components | Graphics | Timer

Publicado em: 22 Julho 2020
no canal de: code-it-philiks
721
20

Here's an appetizer for you!
Learn the basics and explore the fundamentals. Don't be afraid! I believe that you can make this Bouncing Ball program better.

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

GitHub ► https://github.com/Philiks/code-with-...

Oracle's Citation ► https://docs.oracle.com/javase/tutori...

Java Tutorial Series ► https://www.youtube.com/playlist?list...

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬


Why is the JFrame not at the center at 8:30 and what's with the "position" of the code?
Well, there are two things [methods] that caused this behavior the setLocationRelativeTo(null) and pack(). The thing is, we position the JFrame at the center then pack() changes the JFrame's dimension so the JFrame failed to change its location after we have changed its size.


So why do we have to reposition all the codes in JPanel?
To make the code look cleaner. That's it.


Is Math.random() broken?
No, but I am stupid so I misused to hahaha. Well, thankfully Java have 2 RNG and luckily I know how to use one of those two properly.



Oh you want to learn why I asked you to change the ball's initial position?
Well, it's simple. The ball would bounce on the same path if the ball is at the center. This is due to the ball's dimension at JFrame's dimension. It's the ball's and JFrame's fault and not my stupidity ok (?)



What happened to the skinny ball to the end?
Like I said in the video, I just change the stroke's thickness and in order to do that, I have to use Graphics2D and consequently convert my setColor() and drawOval() to Graphics2D. Additionally I added an inner oval with a darker color to have a "body" plus I did some tweaking to make the ball look like a basketball.

So now that you've learned how to bounce a ball, what's next?
In the next video for this series, we will do ________ visualizer.

Thank you for watching!


Nesta página do site você pode assistir ao vídeo on-line Java Swing Components | Graphics | Timer duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário code-it-philiks 22 Julho 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 721 vezes e gostou 20 espectadores. Boa visualização!