SecurityManager類checkAwtEventQueueAccess()方法
- checkAwtEventQueueAccess() 方法在 java.lang 包中可用。
- checkAwtEventQueueAccess() 方法用於通過使用 AWTPermission(“accessEventQueue”) 調用 checkPermission 來訪問 AWT(Abstract Window Toolkit) 事件隊列。
- checkAwtEventQueueAccess() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- checkAwtEventQueueAccess() 方法可能在訪問 AWT 事件隊列時拋出異常。
SecurityException- 當不允許調用線程訪問 AWT 事件隊列時,可能會拋出此異常。
用法:
public void checkAwtEventQueueAccess();
參數:
- 它不接受任何參數。
返回值:
這個方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void checkAwtEventQueueAccess()
// method of SecurityManager
public class CheckAwtEventQueueAccess {
public static void main(String[] args) {
// By using setProperty() method is to set the policy property
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a SecurityManager object
SecurityManager smgr = new SecurityManager();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(smgr);
// By using CheckAwtEventQueueAccess() method is to check
// that awt event queue is accessed or not
smgr.checkAwtEventQueueAccess();
// Display the message when queue is acessible
System.out.println("Not Restricted..");
}
}
輸出
Exception in thread "main" java.security.AccessControlException:access denied ( java.awt.AWTPermission accessEventQueue) at java.security.AccessControlContext.checkPermission(AccessControlConte xt.java:264) at java.security.AccessController.checkPermission(AccessController.java: 427) at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) at java.lang.SecurityManager.checkAwtEventQueueAccess(SecurityManager.ja va:1398) at CheckAwtEventQueueAccess.main(CheckAwtEventQueueAccess.java:18)
相關用法
- Java SecurityManager checkAccept()用法及代碼示例
- Java SecurityManager checkAccess()用法及代碼示例
- Java SecurityManager checkPackageAccess()用法及代碼示例
- Java SecurityManager checkPrintJobAccess()用法及代碼示例
- Java SecurityManager checkSystemClipboardAccess()用法及代碼示例
- Java SecurityManager checkPropertiesAccess()用法及代碼示例
- Java SecurityManager checkLink()用法及代碼示例
- Java SecurityManager checkWrite()用法及代碼示例
- Java SecurityManager checkPropertyAccess()用法及代碼示例
- Java SecurityManager checkSetFactory()用法及代碼示例
- Java SecurityManager checkSecurityAccess()用法及代碼示例
- Java SecurityManager checkPermission()用法及代碼示例
- Java SecurityManager checkRead()用法及代碼示例
- Java SecurityManager checkTopLevelWindow()用法及代碼示例
- Java SecurityManager checkDelete()用法及代碼示例
- Java SecurityManager checkConnect()用法及代碼示例
- Java SecurityManager checkMemberAccess()用法及代碼示例
- Java SecurityManager checkListen()用法及代碼示例
- Java SecurityManager checkMulticast()用法及代碼示例
- Java SecurityManager checkExec()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java SecurityManager checkAwtEventQueueAccess() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。