• Post Reply Bookmark Topic Watch Topic
  • New Topic

communication between classes

 
elwin Ilam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I've got a bit of a noob problem here:

Background story: the code for my checklist application is getting to big, so i'm trying to cut it up into smaller pieces. With each checklist in a different class and the GUI with all the save and load buttons in the main class.

So at the moment I'm working on a little test application to get the communication set up between the classes.
I've got a main class here (which just calls the GUI class), a GUI class and a FormJPanel class

I've got a button in my GUI class and a checkbox in my FormJpanel class.
I want the checkbox to be selected when i press the button...
But somehow I get the 'non-static variable jbutton1 cannot be referenced from a static context' error and I've got no idea how to get rid of it.
And if i make a new instance of the class...it gives me an Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet."

So how to I access the button from the other class without getting either of those errors? I know it should be really easy...but I can't see a way at the moment.

Some advice it much appreciated.
El..

The GUI class (without all the netbeans stuff)

The FormJpanel:









 
Campbell Ritchie
Marshal
Posts: 52589
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I shall move this discussion to the GUIs forum.

Get rid of the classes implementing Listeners; that is bad design, even though you see it in books and the Java™ Tutorials. Also get rid of the actionPerformed method. Add the Listener to your button as an anonymous class. That gets rid of any rubbish like getSource() == yxz.

Don't use NetBeans for designing GUIs until you are more experienced; the code (as you have already seen) is so difficult to understand.

If you want to gain access to an instance field, that must be done in an instance method (or constructor), not a static method. The buttons ought not to be static fields.
Why on earth would you want a button which activates another button?
 
Campbell Ritchie
Marshal
Posts: 52589
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch

You must be invoking the actionPerformed method somehow; since this isn't implemented (NetBeans correctly inserts the Exception here), you suffer the UnsupportedOperationException.
 
elwin Ilam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sweet!
Thanks alot,

I removed the class listeners and replaced them with your anonymous class listeners.
It is nice to see something working again after more than a week of struggling.

I think I'm going to study the basics a bit more before continuing with my big project.
(the project worked pretty well, but I end up with errors I dont understand after a while)

Cheers,
Elwin
 
Campbell Ritchie
Marshal
Posts: 52589
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!