Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

e.getSource() question  RSS feed

 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How do I stop events coming from cbSKU and cbSubCategory?
Here e.getSource() returns JComboBox rather than cbSKU or cbSubCategory.
Any ideas?
Thanks
Jack
 
Claude Moore
Ranch Hand
Posts: 862
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean with "to stop "?
Anyway, you added an anonymous class instance to a specific component. As consequence of this, All listened events may have only a source, i.e. the component you added the listener to. So checking the source of the event is useless. It would ne different if you had added an instance of ItemListener which were shared among more than a single component.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the || on line 6 to &&:

Unless cbSKU == cbSubCategory, your if condition will always be true. After all, (assuming X != Y), something is either not X, or not Y, or not X and not Y. What you want is that the something is not X and not Y.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacky Luk wrote:Here e.getSource() returns JComboBox

No, it doesn't. It returns the source of the event: cbCategory.

System.out then prints cbCategory.toString().
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting this while I want to change the SKU, then the category and subcats will be reset.
And changing cats will setup SKUs and subcats and so on so forth.
There might still be bugs in it.

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the java docs for ConcurrentModificationException to see why it's being thrown (you should always check the docs for any exception you get).
 
Jacky Luk
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody,
I notice that there is a logical bug in my program.
Now I have fixed that, it works okay now.
Jack
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!