Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

More problems with my two frames  RSS feed

 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really appreciate the help I got from my last porblem, I got another
I open another frame with a CheckBoxMenuItem and that works, same with the closing. However, I need the CheckBoxMenuItem to become unchecked when you close the other frame by the x in the titlebar. This is the code I used.

This compiles, but when I try it, I get this exception and it doesn't work, any ideas?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you ever assign a value to the -

at the start of your ColorWindowAdapter?

If you never assign a value to it, you'll get a NullPointerException when you call unCheck() on it later.
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also meant to say that the unCheck is in the class of the other frame.
Plus, what do I need to do to not get the null exception, initialized the paintWindow to null and I still get it
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you initialize it to null, that's not going to prevent a *Null*PointerException...

You're going to have to pass a reference to an actual object of the MyPaint class that the paintWindow reference can point to. You can do this through either a constructor parameter, or through some kind of set method (or, if the ColorWindowAdapter is an inner class, you can access variables in the class containing ColorWindowAdapter). I would recommend simply passing a reference through an argument to the constructor, because then the ColorWindowAdapter created will always have a MyPaint object associated with it (unless you explicitly pass null to the constructor).

 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this would work since I don't see the rest of your code, but couldn't you just subclass the CheckBoxMenuItem and make it a window listener as well? Or make it your primary window listener if that checkbox is the way you open the other window. Then you just have it uncheck itself when the window says it is closing...
Chris
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out, thanks anyway for trying to help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!