• Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox switch statement MouseEvent problem  RSS feed

 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While I went through a tutorial and matched up the syntax to the best of my understanding I am getting errors from NetBeans.

1) 'switch (s) {'
incompatible type, requires int... is it looking for number of how many cases it contains?

2) 'case 'none':'
unclosed character literal, not a statement (all the cases contain this same error)

3) 'addText(msg);' dont need to worry about this, function I am working, another issue.




I appreciate any suggestions
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Hultin wrote:While I went through a tutorial and matched up the syntax to the best of my understanding I am getting errors from NetBeans.

1) 'switch (s) {'
incompatible type, requires int... is it looking for number of how many cases it contains?

...

I appreciate any suggestions


int means the actual values that s can have. not the number of possible values. it can't be a string, s must be an int (integer), or a char which is in one sense the same as an int.


edit: maybe getSelectedIndex() will do it for you. It's a method in the JComboBox() class
 
Ben Hultin
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the suggestion, I made changes to the code as below and now the errors are all gone.






My only problem now is getting the msg to appear in my code_field varibale. setText has worked for me in the past. Any thoughts?
 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are saying that this method is part of a larger class that compiles without any errors, then I don't see a problem with what you have shown, although there may well be a problem elsewhere in the class. Make sure that code_field is properly defined and included in your GUI. That's about all I can say.

p.s. maybe try to verify that the value being assigned to s is indeed one of the cases included in your switch. You can also have a default case at the end which will execute if none of the other cases are satisfied.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!