Radio Check Box Component

The VkRadioBox class provides a simple method for creating radio check boxes (that is, check boxes in which only one toggle at a time can be selected). VkRadioBox is a subclass of VkCheckBox. The only difference between the two classes is that VkRadioBox enforces radio behavior on the toggles it contains.

VkRadioBox provides all of the same functions and data members as VkCheckBox does. You use the VkRadioBox class in the same way that you do the VkCheckBox class.

For example, consider a simple window that contains only a check box with four toggles as shown in Figure 53.

Figure 53. Example Radio Box

Example 42. contains the code used to create this check box.

Example 42. Creating a Radio Box

Code

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>
#include <Vk/VkRadioBox.h>
class RadioBoxWindow: public VkSimpleWindow {
protected:
virtual Widget setUpInterface ( Widget parent );
static String _defaultResources[];
public:
RadioBoxWindow ( const char *name ) : VkSimpleWindow ( name ) { }
~RadioBoxWindow();
virtual const char* className();
};
RadioBoxWindow:: ~RadioBoxWindow()
{ }
const char* RadioBoxWindow::className() { return "RadioBoxWindow"; }
String RadioBoxWindow::_defaultResources[] = {
"*radio*label.labelString: Select one:",
"*radio*one*labelString: First choice",
"*radio*two*labelString: Second choice",
"*radio*three*labelString: Third choice",
"*radio*four*labelString: Fourth choice",
NULL
};
Widget RadioBoxWindow::setUpInterface ( Widget parent )
{
setDefaultResources(parent, _defaultResources);
VkRadioBox *rb = new VkRadioBox("radio", parent);
rb->addItem("one");
rb->addItem("two");
rb->addItem("three");
rb->addItem("four");
rb->show();
return rb->baseWidget();
}
void main ( int argc, char **argv )
{
VkApp *rbApp = new VkApp("radioBoxApp", &argc, argv);
RadioBoxWindow *rbWin = new RadioBoxWindow("radiobox");
rbWin->show();
rbApp->run();
}