Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
When you are developing a control, you must often provide methods to perform actions in your control. For the GroupCheck control, you add a method that disables or enables the controls contained within the GroupBox control based on the checked state of the CheckBox control. The method is called from the setChecked method.
To add a method to a control
Add the following method definition to the GroupCheck control's source code:
public void enableControls(Control start, boolean enable) { for(int i = 0; i < start.getControlCount(); i++) { Control c = start.getControl(i); if(c == groupBox1 || c == checkBox1) { continue; } c.setEnabled(enable); enableControls(c, enable); }}The
enableControlsmethod accepts a control and a boolean value that determines whether the contained controls should be enabled or disabled. When this method is called by thesetCheckedmethod, it is passed the current instance of the GroupCheck control.The
enableControlsmethod begins by looping through all the controls that are contained in thestartcontrol parameter. Within the for loop, the code obtains a contained control using thegetControlmethod with the for loop's current index. If the control is not the GroupCheck control's GroupBox or CheckBox controls, the code enables or disables the specified control based on the value of the enable parameter. Any controls that are contained within this control are then enabled or disabled through a recursive call toenableControls.
The next step is to add code to the constructor.