String key = offset == -1 ? keyStroke : keyStroke.substring( offset + 1 );
I found an example of some code online and it contained this line that I do not understand.
This is a piece of code found in a key binding example. Specifically, "KeyboardAnimation.java" line 37.
This may come across as a dumb question, but I have no idea what is happening here. I could spend a long time doing research, but I feel like this could be fairly easily explained by someone (I can go into more detail about my reasoning, but it's beside the point).
I get that it's setting the variable key
of type String
to something. keyStroke is a String that is formatted the way a keystroke would be:
Parses a string and returns a KeyStroke. The string must have the following >syntax:
* ( | )modifiers := shift | control | ctrl | meta | alt | altGraph
typedID := typed
typedKey := string of length 1 giving Unicode character.
pressedReleasedID := (pressed | released) key
key := KeyEvent key code name, i.e. the name following "VK_".
If typed, pressed or released is not specified, pressed is assumed. Here are >some examples:
"INSERT" => getKeyStroke(KeyEvent.VK_INSERT, 0); "control DELETE" => getKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK); "alt shift X" => getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK); "alt shift released X" => getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true); "typed a" => getKeyStroke('a');
(from: KeyStroke javax.swing.KeyStroke.getKeyStroke(String s))
Now, to get into what I actually don't know: Why does it appear to have a Boolean operator in there? What does the question mark do? What does the colon do?
I feel like this is stuff I should have learned before but haven't...