Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SWITCH STATEMENT

 
AaronMweu Munzaa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys - Any help on this would be highly appreciated:
I am implementing actionPerformed()method and I wanted to use case statements to determine event source (I have buttons, textfields, checkboxes etc in my GUI)...Could anyone tell me how to determine event source(probably using getSource method) then pass it as the argument to my case statements...Please.
Thanks in Advance.
Aaron
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You won't be able to use a switch here, since you'll be comparing event Objects.
For instance:

This is one way to do it, but regardless of which way you choose, you won't be able to use the switch (since switch statements require char, byte, short, or int datatype).
 
AaronMweu Munzaa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Hunter...Helped greatly appreciated.
Aaron
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic