Want my paintComponent to draw rects, ovals and lines but getting a NullPointerException. debugged my code to find which variable might be causing the problem but everything seems to be right.
Obviously not do!! Any help on this would be really appreciated!!
We don't mind if you cross post but do tell us as we all give up our time here for free and would rather not waste it answering a question that has already been answered elsewhere.
Apologies everybody, was unaware and won't be doing this again. I appreciate that everyone is helping out of there own good will and time and won't be cross posting again. Thanks for your help and time code ranchers 👍🏻
Well... from what you've posted it's kinda hard to tell how big your panel is when it's displayed. Perhaps its size is zero, in which case you won't see anything. (Which is your problem statement.) You can fix that by making the panel have a border and making the border be red, so you can see how big the bordered area appears.
And then there's your paintComponent method. We know it's being called because your original post mentioned an exception thrown by it. But I'd still recommend using the @Override annotation to ensure it's actually overriding JPanel's method.
And I'm not sure what that method is supposed to be doing. It looks like it's going through the shapes array and re-drawing them three times. Why the repetition?
You should also note that although you have three entries in the shapes array, there's no guarantee that all three of them will have shapes in them. Actually I'm not clear on what the purpose of the "input" parameter is when you aren't going to display more than three shapes.
Here you are setting shapes[1] to a new MyRect3. However, in the following loop you set shapes[0], shapes[1], and shapes[2], each to yet another new MyRect3 and each of these MyRect3 instances have exactly the same parameters.
[Edit] Sorry, seems that I missed your more recent post that does not have a loop.