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

Bookmark/Search this post with: