|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.j4me.ui.components.Component
org.j4me.ui.components.RadioButton
public class RadioButton
A RadioButton
component lets a user select exactly one choice
from a list. An example of where radio buttons are useful is to select
a logging level. There are a known set of choices and the level is
set to one of them.
Traditionally radio buttons are displayed next to each other in a box. This component forgoes that model to save screen space. Instead the selected option is displayed. If the user pressed a button while the component is highlighted it takes them to a screen, similar to a menu, where the user can choose a different value.
ChoiceGroup
Field Summary | |
---|---|
protected java.util.Vector |
choices
The ordered list of radio button choices. |
protected int |
selected
The index of the currently selected choice. |
Fields inherited from class org.j4me.ui.components.Component |
---|
container, HIGHLIGHTED_BORDER_WIDTH |
Constructor Summary | |
---|---|
RadioButton()
Constructs a radio button component. |
Method Summary | |
---|---|
boolean |
acceptsInput()
Tells if this component accepts user input or not. |
int |
append(java.lang.String choice)
Appends an element to the list of choices. |
void |
delete(int elementNum)
Deletes the element referenced by elementNum . |
void |
deleteAll()
Deletes all elements from the list of choices. |
java.lang.String |
getLabel()
|
protected int[] |
getPreferredComponentSize(Theme theme,
int viewportWidth,
int viewportHeight)
Returns the ideal size for a radio button component. |
int |
getSelectedIndex()
Returns the index number of the element that is selected. |
java.lang.String |
getSelectedValue()
Returns the value of the element that is selected. |
java.lang.String |
getString(int elementNum)
Gets the String for the element referenced by
elementNum . |
protected void |
hideNotify()
An event raised whenever the component is removed from the screen. |
void |
insert(int elementNum,
java.lang.String choice)
Inserts an element into the list of choices just prior to the element specified. |
void |
keyPressed(int keyCode)
Called when a key is pressed. |
protected void |
paintComponent(javax.microedition.lcdui.Graphics g,
Theme theme,
int width,
int height,
boolean selected)
Paints the radio button component. |
void |
pointerPressed(int x,
int y)
Called when the pointer is pressed. |
protected void |
select()
Called when the radio button's value is being edited. |
void |
set(int elementNum,
java.lang.String choice)
Sets the element referenced by elementNum , replacing the
previous contents of the element. |
void |
setLabel(java.lang.String label)
|
void |
setSelectedIndex(int elementNum)
Sets the index of the selected element. |
protected void |
showNotify()
An event raised whenever the component is made visible on the screen. |
int |
size()
Returns the number of elements to choose from. |
Methods inherited from class org.j4me.ui.components.Component |
---|
getHeight, getHorizontalAlignment, getPreferredSize, getScreen, getWidth, getX, getY, invalidate, isShown, keyReleased, keyRepeated, paint, paintRect, pointerDragged, pointerReleased, repaint, setHorizontalAlignment, visible |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Vector choices
protected int selected
Constructor Detail |
---|
public RadioButton()
Method Detail |
---|
public java.lang.String getLabel()
null
there is no text.public void setLabel(java.lang.String label)
label
- is the text that appears above the radio button.
If null
there will be no text.public int size()
public java.lang.String getString(int elementNum)
String
for the element referenced by
elementNum
.
elementNum
- is the index of the element to be queried.
public int append(java.lang.String choice)
choice
- is the string to be added.
public void insert(int elementNum, java.lang.String choice)
elementNum
- is the index of the element where insertion
is to occur.choice
- is the string to be inserted.public void delete(int elementNum)
elementNum
.
elementNum
- is the index of the element to be deleted.public void deleteAll()
public void set(int elementNum, java.lang.String choice)
elementNum
, replacing the
previous contents of the element.
elementNum
- the index of the element to be set.choice
- is the string to be set.public int getSelectedIndex()
public java.lang.String getSelectedValue()
public void setSelectedIndex(int elementNum)
elementNum
- is the currently selected element.protected void showNotify()
paintComponent
method.
showNotify
in class Component
Component.showNotify()
protected void hideNotify()
hideNotify
in class Component
Component.hideNotify()
protected void paintComponent(javax.microedition.lcdui.Graphics g, Theme theme, int width, int height, boolean selected)
Changing the selected value is done on a different screen. Therefore it is not painted here.
paintComponent
in class Component
g
- is the Graphics
object to be used for rendering the item.theme
- is the application's theme. Use it to get fonts and colors.width
- is the width, in pixels, to paint the component.height
- is the height, in pixels, to paint the component.selected
- is true
when this components is currently selected
and false
when it is not.Component.paintComponent(javax.microedition.lcdui.Graphics, org.j4me.ui.Theme, int, int, boolean)
protected int[] getPreferredComponentSize(Theme theme, int viewportWidth, int viewportHeight)
getPreferredComponentSize
in class Component
theme
- is the application's Theme
.viewportWidth
- is the width of the viewable area, in pixels,
the component can use.viewportHeight
- is the height of the viewable area, in pixels,
the component can use.
Component.getPreferredComponentSize(org.j4me.ui.Theme, int, int)
public boolean acceptsInput()
Component
The default implementation returns false
. Override this method
to return true
if the component accepts input.
acceptsInput
in class Component
true
because this component accepts user input.public void keyPressed(int keyCode)
keyPressed
in class Component
keyCode
- is the key code of the key that was pressed.public void pointerPressed(int x, int y)
pointerPressed
in class Component
x
- is the horizontal location where the pointer was pressed
relative to the top-left corner of the component.y
- is the vertical location where the pointer was pressed
relative to the top-left corner of the component.protected void select()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |