Java Swing Components | Graphics | Timer

Published: 22 July 2020
on channel: 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!


On this page of the site you can watch the video online Java Swing Components | Graphics | Timer with a duration of hours minute second in good quality, which was uploaded by the user code-it-philiks 22 July 2020, share the link with friends and acquaintances, this video has already been watched 721 times on youtube and it was liked by 20 viewers. Enjoy your viewing!