Home » Java programming language

Java SecurityManager checkTopLevelWindow() method with example

SecurityManager Class checkTopLevelWindow() method: Here, we are going to learn about the checkTopLevelWindow() method of SecurityManager Class with its syntax and example.
Submitted by Preeti Jain, on December 18, 2019

SecurityManager Class checkTopLevelWindow() method

  • checkTopLevelWindow() method is available in java.lang package.
  • checkTopLevelWindow() method invokes checkPermission with the AWTPermission("showWindowWithoutWarningBanner") permission.
  • checkTopLevelWindow() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • checkTopLevelWindow() method may throw an exception at the time of showing the window.
    NullPointerException – This exception may throw when the given parameter is null.

Syntax:

    public boolean checkTopLevelWindow(Object e_win);

Parameter(s):

  • Object e_win – represents the newly created window.

Return value:

The return type of this method is boolean, it returns true when the caller is genuine or trusted to bring the top-level window denoted by the given parameter and window will be shown otherwise it returns false when the calling thread is not genuine or non-trusted but whether the window will be shown or not depend on calling thread.

Example:

// Java program to demonstrate the example 
// of boolean checkTopLevelWindow(Object e_win)
// method of SecurityManager 

import java.security.*;

public class CheckTopLevelWindow extends SecurityManager {
    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 CheckTopLevelWindow object
        CheckTopLevelWindow ctlw = new CheckTopLevelWindow();

        // By using setSecurityManager() method is to set the
        // security manager
        System.setSecurityManager(ctlw);

        // By using checkTopLevelWindow(Object) method is to //check 
        // that top level window is setor not
        boolean e_win = ctlw.checkTopLevelWindow("Window");

        // Display e_win
        System.out.println("e_win = " + e_win);
    }
}

Output

e_win = false



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.