Sorry there's so much code... I have a feeling it has something to do with the way I'm handling the event in the actionPerformed method (right at the bottom of Draw.java). Thanks for any help!
The problem is with private Shape shape; - you never initialize it. Where is your line that says "shap = new Shape[...]"?
If you don't want to limit the number of shapes to 5, you may want to consider using a List:
It has its own counter for the number of elements to (shapes.size()), so numOfShapes becomes obsolete.
Edit: after adding that line your code still does not work. That's because you're not overriding paintComponent in Draw - JFrame has no such method. You need paint instead; also don't forget to call super.paint(g); first.
Also, don't make x and y static. That way all your shapes will have the same coordinates.
...and You also override paintComponent of JFrame but... there's no such method to override
Use @Override annotation just before method You are overrideing (paintComponent) and You'll see what I mean!
you should override "paintComponents" method if You want draw on JFrame but I suggest to add JPanel to JFrame and draw on that panel.
Bartek Myszkowski wrote:
You should override "paintComponent[size=14]s" method if You want draw on JFrame
No, never. The method paintComponents has an entirely different role.
The correct way to do custom painting in Swing is to override paintComponent of a JComponent (or any subclass of it).
Rob Prime wrote:
Darryl Burke wrote:The correct way to do custom painting in Swing is to override paintComponents of a JComponent (or any subclass of it).
Shouldn't that be paintComponent?
Bartek is right though, the best way is to use a JPanel subclass and extend its paintComponent method.
Yup, I had a typo in the worst possible place
Thanks for the info on the shapes array, that's a dumb mistake on my part. Personally I'd rather program encryption algorithms thank program Swing components. But I know it's useful and I need to know it.
I'm sorry Rob, after reading your post again more carefully, it clicked in my head to change my paintComponents to paint(). I got something showing up on the screen, I think I can take it from here. Thanks a lot everyone!
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Rocket Oven Kickstarter - from the trailbosshttps://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss