• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActionEvent

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!

Where can I find a full list of all the Strings that ActionEvent throws?

For example, in the Sun online tutorial on ComboBox, the string "comBoxChanged" is used. I had no idea this is the exact strings ActionEvent throws for comboBox events.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really understand what you're asking here. The ActionEvent class doesn't "throw" anything. Events, in Java, are typically referred to as "fired" and exceptions are "thrown."
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know the answer, but I believe I can clarify the question.

A JComboBox has a protected String field called actionCommand. The accessor and mutator methods are getActionCommand() and setActionCommand(String s).

When a new JComboBox is created, the default value of actionCommand is "comboBoxChanged". This can be observed by simply creating a new JComboBox using the no-args constructor, then printing out the value of getActionCommand().

So I believe Karen's question is: Where does this default value come from?

I would expect this field to be null. I've searched the API, but can't find anything that explains how it's initialized.

Note: The Java Tutorial example appears to be here:
http://java.sun.com/docs/books/tutorial/uiswing/learn/example5.html
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, using the actionCommand string to decide what to do is quite rare in my experience, with anonymous inner classes.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to clarify, Strings don't get thrown, exceptions do. And ActionEvent could throw just about anything depending on how you're using it.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Carman:
Well, using the actionCommand string to decide what to do is quite rare in my experience, with anonymous inner classes.


Yeah, I was surprised to see this (although maybe I shouldn't have been, since Sun's Swing Tutorial is a strangely jumbled concoction). But I'm still curious about the apparent lack of documentation.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't count on this default -- counting on undocumented things is always a bad idea. Besides, there's a setActionCommand() method, so the default is just that -- a changeable default.
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I shouldn't have used the keyword "throw" here. I used it on a general term. Sorry, guys.

Anyway, I just am at a loss how I could figure out that the word "comboBoxChanged" is a default value without printing the value of getActionCommand().

How would I know that, in this instance, not to use setActionCommand()?

So, I'll just repeat marc webber's :
Where does this default value come from?
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karen Baog:
... Where does this default value come from?


These "magic values" bother me. But as Ernest pointed out, the best approach here is to use setActionCommand("My String") so that you know what the field contains. Avoid using a default value that you cannot predict or depend on.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karen Baog:
Hi everyone,

I shouldn't have used the keyword "throw" here. I used it on a general term. Sorry, guys.

Anyway, I just am at a loss how I could figure out that the word "comboBoxChanged" is a default value without printing the value of getActionCommand().

How would I know that, in this instance, not to use setActionCommand()?

So, I'll just repeat marc webber's :
Where does this default value come from?



I would say, don't worry about it. You probably won't ever really use actionCommand Strings in your "real" development anyway. I wouldn't lose any sleep over this. But, their previous advice about actually setting the actionCommand String so that you know what it is sounds good to me too.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing/AWT...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic