Java Swing Components | Graphics | Timer

Veröffentlicht am: 22 Juli 2020
auf dem Kanal: 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!


Auf dieser Seite können Sie das Online-Video Java Swing Components | Graphics | Timer mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer code-it-philiks 22 Juli 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 721 Mal angesehen und es wurde von 20 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!