Help on line detection

There are a lot of bouncing ball tutorials for Processing – see for example the examples section. Start with the simplest example first:

In general, the principle to detect if the ball hits the walls is circle-line collision detection, covered with a working example in this guide:

You may also be interested in one of several video tutorials on the bouncing ball problem: