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

Bookmark/Search this post with: