You could probably do it either way. Which way did you try?
Type: Posts; User: KevinWorkman
You could probably do it either way. Which way did you try?
Well, a good place to start with custom painting is here: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Glad you got it figured out. And just to show you the process, I figured that out by putting a print statement inside the constructor. When I saw that printed out twice, I knew something was wrong.
I am behind a firewall that prevents me from viewing that type of link. Besides, you should make it as easy as possible for other people to help you. The best way to do that is by creating an SSCCE....
You haven't posted your code for MyShape, so I can't run your program.
I suggest boiling your problem down to an SSCCE and posting that.
Without seeing an SSCCE, the best I can do is repeat...
Java doesn't magically know how to print an object. To tell it how to do that, you have to override the toString() method.
You're printing out the value of myShape. But the variable that's null is...
Are you sure the setShape() method is called before the stateChanged() method? What happens if you don't click a menu first?
Well, when is that setShape() method actually called? Again, use a debugger or add print statements like I showed you to figure out. You'll find that this line:
System.out.println("here");
will...
Your error means that a variable you're dereferencing (using the dot operator) is null. You can't dereference a null variable.
The only variable you're dereferencing in this line is your theShape...
What variable is null on line 79 of MyControlPanel.java?
You can use a debugger, or some print statements, to figure it out.