Class Button
java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<Button>
com.googlecode.lanterna.gui2.AbstractInteractableComponent<Button>
com.googlecode.lanterna.gui2.Button
- All Implemented Interfaces:
Component, Interactable, TextGUIElement
Simple labeled button that the user can trigger by pressing the Enter or the Spacebar key on the keyboard when the
component is in focus. You can specify an initial action through one of the constructors and you can also add
additional actions to the button using
addListener(Listener). To remove a previously attached action, use
removeListener(Listener).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceHelper interface that doesn't add any new methods but makes coding new button renderers a little bit more clearstatic classThis is the default button renderer that is used if you don't override anything.static classAlternative button renderer that displays buttons with just the label and minimal decorationstatic interfaceListener interface that can be used to catch user events on the buttonNested classes/interfaces inherited from interface Interactable
Interactable.FocusChangeDirection, Interactable.Result -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Button.Listener listener) Adds a listener to notify when the button is triggered; the listeners will be called serially in the order they were addedprotected Button.ButtonRendererWhen you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).Returns, in local coordinates, where to put the cursor on the screen when this component has focus.getLabel()Returns the label current assigned to the buttonhandleKeyStroke(KeyStroke keyStroke) This method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus.booleanremoveListener(Button.Listener listener) Removes a listener from the button's list of listeners to call when the button is triggered.final voidUpdates the label on the button to the specified stringtoString()protected voidMethods inherited from class AbstractInteractableComponent
afterEnterFocus, afterLeaveFocus, getInputFilter, getRenderer, handleInput, isActivationStroke, isEnabled, isFocusable, isFocused, isKeyboardActivationStroke, isMouseActivationStroke, isMouseDown, isMouseDrag, isMouseMove, isMouseUp, onEnterFocus, onLeaveFocus, setEnabled, setInputFilter, takeFocusMethods inherited from class AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorderMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Component
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorderMethods inherited from interface TextGUIElement
draw, isInvalid
-
Field Details
-
listeners
-
label
-
-
Constructor Details
-
Button
Creates a new button with a specific label and no initially attached action.- Parameters:
label- Label to put on the button
-
Button
-
-
Method Details
-
createDefaultRenderer
Description copied from class:AbstractComponentWhen you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRendererin classAbstractInteractableComponent<Button>- Returns:
- Renderer to use when sizing and drawing this component
-
getCursorLocation
Description copied from interface:InteractableReturns, in local coordinates, where to put the cursor on the screen when this component has focus. If null, the cursor should be hidden. If you component is 5x1 and you want to have the cursor in the middle (when in focus), return [2,0]. The GUI system will convert the position to global coordinates.- Specified by:
getCursorLocationin interfaceInteractable- Overrides:
getCursorLocationin classAbstractInteractableComponent<Button>- Returns:
- Coordinates of where to place the cursor when this component has focus
-
handleKeyStroke
Description copied from class:AbstractInteractableComponentThis method can be overridden to handle various user input (mostly from the keyboard) when this component is in focus. The input method from the interface,handleInput(..)is final inAbstractInteractableComponentto ensure the input filter is properly handled. If the filter decides that this event should be processed, it will call this method.- Overrides:
handleKeyStrokein classAbstractInteractableComponent<Button>- Parameters:
keyStroke- What input was entered by the user- Returns:
- Result of processing the key-stroke
-
triggerActions
protected void triggerActions() -
setLabel
Updates the label on the button to the specified string- Parameters:
label- New label to use on the button
-
addListener
Adds a listener to notify when the button is triggered; the listeners will be called serially in the order they were added- Parameters:
listener- Listener to call when the button is triggered
-
removeListener
Removes a listener from the button's list of listeners to call when the button is triggered. If the listener list doesn't contain the listener specified, this call do with do nothing.- Parameters:
listener- Listener to remove from this button's listener list- Returns:
trueif this button contained the specified listener
-
getLabel
Returns the label current assigned to the button- Returns:
- Label currently used by the button
-
toString
-