Package totalcross.ui
Class Radio
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Radio
-
- All Implemented Interfaces:
MaterialEffect.SideEffect,TextControl
public class Radio extends Control implements TextControl, MaterialEffect.SideEffect
Radio is a radio control. Radios can be grouped together using a RadioGroupController.Here is an example showing a radio being used:
public class MyProgram extends MainWindow { RadioGroupController rgGender; public void initUI() { rgGender = new RadioGroupController(); add(new Radio("Male", rgGender), LEFT, AFTER); add(new Radio("Female", rgGender), AFTER+2, SAME); rgGender.setSelectedIndex(radioMale); // activate the specified one. } public void onEvent(Event event) { if (event.type == ControlEvent.PRESSED && (event.target instanceof Radio) && ((Radio)event.target).getRadioGroup() == rgGender) { boolean male = rgGender.getSelectedIndex() == 0; ... handle radio Male being pressed- See Also:
RadioGroupController
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanautoSplitintcheckColorSet to the color of the check, if you want to make it different of the foreground color.booleanleftJustifySet to true to left justify this control if the width is above the preferred one.inttextColorSets the text color of the check.-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description Radio(java.lang.String text)Creates a radio control displaying the given text.Radio(java.lang.String text, RadioGroupController radioGroup)Creates a radio control with the given text attached to the given RadioGroupController
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this control, checking it if clearValueInt is 1.intgetPreferredHeight()returns the preferred height of this control.intgetPreferredWidth()returns the preferred width of this control.RadioGroupControllergetRadioGroup()Returns the RadioGroupController that this radio belongs to, or null if none.java.lang.StringgetText()Gets the text displayed in the radio.booleanisChecked()Returns the checked state of the control.protected voidonBoundsChanged(boolean screenChanged)Called after a setRect.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called by the system to pass events to the radio control.protected voidonFontChanged()Called after a setFontvoidonPaint(Graphics g)Called by the system to draw the radio control.voidsetChecked(boolean checked)Sets the checked state of the control.voidsetChecked(boolean checked, boolean sendPress)Sets the checked state of the control, and send the press event if desired.voidsetText(java.lang.String text)Sets the text.voidsidePaint(Graphics g, int alpha)voidsideStart()voidsideStop()voidsplit(int maxWidth)Splits the text to the given width.-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
autoSplit
public boolean autoSplit
-
textColor
public int textColor
Sets the text color of the check. Defaults to the foreground color.- Since:
- TotalCross 2.0.
-
checkColor
public int checkColor
Set to the color of the check, if you want to make it different of the foreground color.- Since:
- TotalCross 1.3
-
leftJustify
public boolean leftJustify
Set to true to left justify this control if the width is above the preferred one.
-
-
Constructor Detail
-
Radio
public Radio(java.lang.String text)
Creates a radio control displaying the given text.
-
Radio
public Radio(java.lang.String text, RadioGroupController radioGroup)Creates a radio control with the given text attached to the given RadioGroupController
-
-
Method Detail
-
getRadioGroup
public RadioGroupController getRadioGroup()
Returns the RadioGroupController that this radio belongs to, or null if none.
-
setText
public void setText(java.lang.String text)
Sets the text.- Specified by:
setTextin interfaceTextControl
-
getText
public java.lang.String getText()
Gets the text displayed in the radio.- Specified by:
getTextin interfaceTextControl
-
isChecked
public boolean isChecked()
Returns the checked state of the control.
-
setChecked
public void setChecked(boolean checked)
Sets the checked state of the control.
-
setChecked
public void setChecked(boolean checked, boolean sendPress)Sets the checked state of the control, and send the press event if desired.
-
getPreferredWidth
public int getPreferredWidth()
returns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
returns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
onEvent
public void onEvent(Event event)
Called by the system to pass events to the radio control.
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
Description copied from class:ControlCalled after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled- Overrides:
onColorsChangedin classControl
-
onFontChanged
protected void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
onPaint
public void onPaint(Graphics g)
Called by the system to draw the radio control.
-
clear
public void clear()
Clears this control, checking it if clearValueInt is 1.
-
sideStart
public void sideStart()
- Specified by:
sideStartin interfaceMaterialEffect.SideEffect
-
sideStop
public void sideStop()
- Specified by:
sideStopin interfaceMaterialEffect.SideEffect
-
onBoundsChanged
protected void onBoundsChanged(boolean screenChanged)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
split
public void split(int maxWidth)
Splits the text to the given width.- Since:
- TotalCross 4.2.0
- See Also:
autoSplit
-
sidePaint
public void sidePaint(Graphics g, int alpha)
- Specified by:
sidePaintin interfaceMaterialEffect.SideEffect
-
-