jcontrol.ui.vole
Class RadioButton

java.lang.Object
  extended by jcontrol.ui.vole.Component
      extended by jcontrol.ui.vole.RadioButton

public class RadioButton
extends Component

A radio button is a graphical component that can be in either an "on" (true) or "off" (false) state. When a radio button's state is changed to "on", the comprising Container takes care that all other contained radio buttons are set to "off". When the user changes the state, an ActionEvent of type STATE_CHANGED is fired.

(c) Copyright 2003-2007 DOMOLOGIC GmbH


Field Summary
 
Fields inherited from class jcontrol.ui.vole.Component
eventQueue, focusOwner, font, g, height, listener, parent, visible, width, x, y
 
Constructor Summary
RadioButton(String label, int x, int y)
          Create a new labeled RadioButton which is initially "off".
RadioButton(String label, int x, int y, int width, int height)
          Create a new labeled RadioButton with specified bounds which is initially "off".
 
Method Summary
 boolean getState()
          Get the current state of this RadioButton.
 boolean onKeyEvent(KeyEvent e)
          Catch key events.
 void paint()
          Paint the radio button.
 void setActionListener(ActionListener listener)
          Add an ActionListener to the radio button.
 void setLabel(String label)
          Change the label if this radio button.
 void setState(boolean state)
          Set the state of this RadioButton to "on" (true) or "off" (false).
 void validate()
          Compute this component's preferred size and assign internal values width and height.
 
Methods inherited from class jcontrol.ui.vole.Component
getBounds, getParent, isVisible, onActionEvent, remove, removeFocus, requestFocus, setBounds, setFont, setGraphics, setParent, setVisible, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notifyAll, toString, wait
 

Constructor Detail

RadioButton

public RadioButton(String label,
                   int x,
                   int y)
Create a new labeled RadioButton which is initially "off". When no width and height are specified, a preferred size depending on the label dimensions is calculated.

Parameters:
label - A String that is written on the RadioButton.
x - The x-coordinate of this RadioButton.
y - The y-coordinate of this RadioButton.

RadioButton

public RadioButton(String label,
                   int x,
                   int y,
                   int width,
                   int height)
Create a new labeled RadioButton with specified bounds which is initially "off".

Parameters:
label - A String that is written on the RadioButton.
x - The x-coordinate of this RadioButton.
y - The y-coordinate of this RadioButton.
width - The width of this RadioButton.
height - The height of this RadioButton.
Method Detail

setState

public void setState(boolean state)
Set the state of this RadioButton to "on" (true) or "off" (false).

Parameters:
state - The new state of this radio button.

setLabel

public void setLabel(String label)
Change the label if this radio button.

Parameters:
label - The new label or null if the button has no label.

getState

public boolean getState()
Get the current state of this RadioButton.

Returns:
The current state of the radio button.

paint

public void paint()
Paint the radio button.

Overrides:
paint in class Component

validate

public void validate()
Compute this component's preferred size and assign internal values width and height.

Overrides:
validate in class Component

setActionListener

public void setActionListener(ActionListener listener)
Add an ActionListener to the radio button. It will receive STATE_CHANGED action events when the state has changed.

Parameters:
listener - The new ActionListener or null.

onKeyEvent

public boolean onKeyEvent(KeyEvent e)
Catch key events.

Overrides:
onKeyEvent in class Component
Parameters:
e - The KeyEvent.
Returns:
If this method returns true, the KeyEvent is handled by the super Container.