/*
Determine If The Checkbox Is Enabled Example
This java example shows how to determine if the checkbox is enabled or not
using isEnabled method.
*/
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Checkbox;
/*
<applet code="DetermineIfCheckboxEnabled" width=100 height=200>
</applet>
*/
public class DetermineIfCheckboxEnabled extends Applet{
boolean isCheckbox1Enabled;
boolean isCheckbox2Enabled;
public void init(){
//create Checkboxes
Checkbox Checkbox1 = new Checkbox("Checkbox 1");
Checkbox Checkbox2 = new Checkbox("Checkbox 2");
//add Checkboxes
add(Checkbox1);
add(Checkbox2);
Checkbox1.setEnabled(false);
/*
* To determine if the Checkbox is enabled or not use
* boolean isEnabled() method.
*/
isCheckbox1Enabled = Checkbox1.isEnabled();
isCheckbox2Enabled = Checkbox2.isEnabled();
}
public void paint(Graphics g){
g.drawString("Is Checkbox 1 enabled? " + isCheckbox1Enabled, 10,50);
g.drawString("Is Checkbox 2 enabled? " + isCheckbox2Enabled, 10,70);
}
}
Example Output

Bookmark/Search this post with: