0

Per SPL, setActionCommand means: "Sets the action command to the indicated string. If the string is not empty, activating the interactor generates a GActionEvent.

Usage:

setActionCommand(interactor, cmd);"

An example from pset3 is buttons.c:

GButton button = newGButton("Button")

setActionCommand(button, "click");"

Per the walkthrough from Daven, "click" means a unique identifier being associated with the button.

I'm confused with what setActionCommand does. Does it mean that if the button is clicked, the button is called "click"? Or that when it is clicked, the state is "click"?

And when it says "if (strcmp(getActionCommand(event), "click" ==0)", is that checking if the button is in the "clicked/on" stage?

Thank you.

2

Does it mean that if the button is clicked, the button is called "click"? Or that when it is clicked, the state is "click"?

Not really. The setActionCommand function just sets a unique identifier that is associated with the event that is generated by activating the GObject in question (in this case, the GButton).

In other words, when the button is activated (e.g., by clicking it, hitting Enter on it, etc), an event is generated and the information for that event is stored into an instance of type GActionEvent. This information contains the unique identifier (or the so-called action command).

You can access this action command by calling the function getActionCommand and passing in the event as an argument to it. This function returns a string that is exactly the action command that was specified for that button (if any).

And when it says if (strcmp(getActionCommand(event), "click" ==0), is that checking if the button is in the "clicked/on" stage?

Not exactly. strcmp takes 2 strings and returns 0 if they're identical. Recall that getActionCommand returns the string that represents the action command that was specified for the button.

This tells us that this line just checks whether the action command of the current event is the same action command that we specified for our button in which case the button would have been activated and we take an appropriate action (in this case, printing out the string "button was clicked" on the screen).

1
  • Thanks Kareem, that solves it completely for me :)
    – AU786
    Apr 29 '15 at 16:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .