Loading...
Logo
Processing Forum
Howdy,

I would like to use radio buttons but cannot find an example where they actually perform an action when selected.

The interfascia documentation provides an example of selectable buttons:

import interfascia.*; GUIController c; IFRadioController rc; IFRadioButton b1, b2, b3; void setup() { c = new GUIController(this); rc = new IFRadioController("Selector"); b1 = new IFRadioButton("One", 30, 20, rc); b2 = new IFRadioButton("Two", 30, 40, rc); b3 = new IFRadioButton("Three", 30, 60, rc); c.add(rc); }
The example shows buttons but it doesn't show how to detect input and perform an action. If you have time I'd appreciate some guidance.

Thank you.

KB

Replies(4)

getSelectedIndex();

The getSelectedIndex() method returns an int, which is the numerical index of the currently selected RadioButton. If none is selected, its value is -1.

deselectAll();

The deselectAll() method deselects the currently selected radio button so no buttons are selected.

addActionListener(Object listener);

adds an action listener Object which receives GUIEvents when a radio button is clicked. You must implement the actionPerformed() method in order to receive events from the radio controller.

listener, the object that events are sent to (usually 'this').

 From above I think you need actionPerformed() method with a getSelectedIndex() call to determine the button selection.


See the button example for an example for the actionPerformed() method. 

I suggest that you use either ControlP5 or G4P rather than Interfacia.

The reason I suggest this is that the latest version of Interfacia was released in 2006 and there are bugs in the Button control. In other words this library no longer appears to be maintained. I base these statements on the information I got by following the links from the Processing website.

The other two I suggested are both popular and are both being maintained by the authors. My preference is G4P (but then I am biased since I am the author) because it has a companion tool GUI Builder that makes it easy and quick to use.


Thank you both. Quarks, I downloaded your library and will give it a go. Thank you for creating G4P. I will only ask for help if I really hit a wall.

KB
Quarks,

Thank you for creating such a powerful tool, I was amazed how it builds the code for you. 2 questions if you have time:

1. can you show me a simple example of option buttons that do things, ie. change window size or background color?

2. does your tool allow a sketch that uses it to be converted into an applet for Mac or windows?

Again, thank you. We are all busy these days and I appreciate your time.

KB.