Because startPoint and endPoint are defined locally to the loop which you leave when you go on to process the "brush" part of paintComponent. They both therefore become null , and you only process your brush logic if they AREN'T null (which they are , because they're out of scope) .
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad: