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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com