private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode)
     throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (mode == null) throw new NullPointerException("mode must be non-null");
     DisplayMode old_mode = current_mode;
     current_mode = mode;
     boolean was_fullscreen = isFullscreen();
     Display.fullscreen = fullscreen;
     if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) {
       if (!isCreated()) return;
       destroyWindow();
       try {
         if (isFullscreen()) {
           switchDisplayMode();
         } else {
           display_impl.resetDisplayMode();
         }
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
 /**
  * Set the current display mode. If no OpenGL context has been created, the given mode will apply
  * to the context when create() is called, and no immediate mode switching will happen. If there
  * is a context already, it will be resized according to the given mode. If the context is also a
  * fullscreen context, the mode will also be switched immediately. The native cursor position is
  * also reset.
  *
  * @param mode The new display mode to set
  * @throws LWJGLException if the display mode could not be set
  */
 public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (mode == null) throw new NullPointerException("mode must be non-null");
     boolean was_fullscreen = isFullscreen();
     current_mode = mode;
     if (isCreated()) {
       destroyWindow();
       // If mode is not fullscreen capable, make sure we are in windowed mode
       try {
         if (was_fullscreen && !isFullscreen()) display_impl.resetDisplayMode();
         else if (isFullscreen()) switchDisplayMode();
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
 /**
  * Set the parent of the Display. If parent is null, the Display will appear as a top level
  * window. If parent is not null, the Display is made a child of the parent. A parent's
  * isDisplayable() must be true when setParent() is called and remain true until setParent() is
  * called again with null or a different parent. This generally means that the parent component
  * must remain added to it's parent container.
  *
  * <p>It is not advisable to call this method from an AWT thread, since the context will be made
  * current on the thread and it is difficult to predict which AWT thread will process any given
  * AWT event.
  *
  * <p>While the Display is in fullscreen mode, the current parent will be ignored. Additionally,
  * when a non null parent is specified, the Dispaly will inherit the size of the parent,
  * disregarding the currently set display mode.
  *
  * <p>
  */
 public static void setParent(Canvas parent) throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (Display.parent != parent) {
       Display.parent = parent;
       if (!isCreated()) return;
       destroyWindow();
       try {
         if (isFullscreen()) {
           switchDisplayMode();
         } else {
           display_impl.resetDisplayMode();
         }
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
 /**
  * Destroy the Display. After this call, there will be no current GL rendering context, regardless
  * of whether the Display was the current rendering context.
  */
 public static void destroy() {
   if (isCreated()) {
     drawable.destroy();
   }
 }