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!
In questa pagina del sito puoi guardare il video online Java Swing Components | Graphics | Timer della durata di ore minuti seconda in buona qualità , che l'utente ha caricato code-it-philiks 22 luglio 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 721 volte e gli è piaciuto 20 spettatori. Buona visione!