Java SecurityManager checkTopLevelWindow()方法与示例
SecurityManager类checkTopLevelWindow()方法
checkTopLevelWindow()方法在java.lang包中可用。
checkTopLevelWindow()方法使用AWTPermission(“showWindowWithoutWarningBanner”)权限调用checkPermission。
checkTopLevelWindow()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
在显示窗口时,checkTopLevelWindow()方法可能会引发异常。
NullPointerException-如果给定参数为null,则可能引发此异常。
语法:
public boolean checkTopLevelWindow(Object e_win);
参数:
对象e_win–代表新创建的窗口。
返回值:
此方法的返回类型为boolean,当调用者是真实的或可信任的以带来给定参数表示的顶级窗口时,它返回true,并且将显示该窗口;否则,当调用线程不是真实的或非真实的线程时,它返回false。受信任,但是否显示窗口取决于调用线程。
示例
//Java程序演示示例
//booleancheckTopLevelWindow(Objecte_win)
//SecurityManager的方法
import java.security.*;
public class CheckTopLevelWindow extends SecurityManager {
public static void main(String[] args) {
//通过使用setProperty()方法是设置策略属性
//与安全经理
System.setProperty("java.security.policy", "file:/C:/java.policy");
//实例化一个CheckTopLevelWindow对象
CheckTopLevelWindow ctlw = new CheckTopLevelWindow();
//通过使用setSecurityManager()方法是设置
//安全经理
System.setSecurityManager(ctlw);
// By using checkTopLevelWindow(Object) method is to //检查
//该顶级窗口是设置还是不设置
boolean e_win = ctlw.checkTopLevelWindow("Window");
//显示e_win-
System.out.println("e_win = " + e_win);
}
}输出结果
e_win = false
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西