Bouncing Thread Example

In this section, we are going to develop a small Java Graphics application
that creates a ball which bounce with the help of thread
in Graphics.

In the example, a method contentPane() is defined that contains the canvas in the center of the frame. Two
Radio Buttons Start and Stop are
defined in the panel. On pushing the button 'Start', class ActionListener
is called and the ball starts bouncing. On pushing 'Stop', ActionListener
is called and the frame will get close.

The contentPane.add(panel,
"North") gives the position to the panel of the buttons on the
frame. The dimensions for the ball are defined. The shape of the ball is given
by graphics.fillOval(p, q, P, Q).