Example #1
0
  public static DisplayMode[] getDisplayModes() {
    GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = genv.getDefaultScreenDevice();
    java.awt.DisplayMode desktopMode = device.getDisplayMode();
    java.awt.DisplayMode[] displayModes = device.getDisplayModes();
    ArrayList<DisplayMode> modes = new ArrayList<DisplayMode>();
    int idx = 0;
    for (java.awt.DisplayMode mode : displayModes) {
      boolean duplicate = false;
      for (int i = 0; i < modes.size(); i++) {
        if (modes.get(i).width == mode.getWidth()
            && modes.get(i).height == mode.getHeight()
            && modes.get(i).bitsPerPixel == mode.getBitDepth()) {
          duplicate = true;
          break;
        }
      }
      if (duplicate) continue;
      if (mode.getBitDepth() != desktopMode.getBitDepth()) continue;
      modes.add(
          new LwjglApplicationConfigurationDisplayMode(
              mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth()));
    }

    return modes.toArray(new DisplayMode[modes.size()]);
  }
Example #2
0
  public static BufferedImage convertIconToBufferedImage(final Icon icon) {

    if (icon == null) {
      return null;
    }
    if (icon instanceof ImageIcon) {
      final Image ret = ((ImageIcon) icon).getImage();
      if (ret instanceof BufferedImage) {
        return (BufferedImage) ret;
      }
    }
    final int w = icon.getIconWidth();
    final int h = icon.getIconHeight();
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final BufferedImage image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);

    final Graphics2D g = image.createGraphics();
    g.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    // g.setColor(Color.RED);
    // g.fillRect(0, 0, w, h);
    icon.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
  }
Example #3
0
  public PlateauGraphique(/*int largeur, int hauteur,*/ Monopoly m) {

    this.m = m;
    cases = new ArrayList<CaseGraphique>();

    setExtendedState(JFrame.MAXIMIZED_BOTH);
    GraphicsDevice device =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    device.setFullScreenWindow(this);

    this.largeur = getContentPane().getWidth();
    this.hauteur = getContentPane().getHeight();

    if (largeur > hauteur) largeur = hauteur;
    else hauteur = largeur;

    initialiser();

    addComponents(getContentPane());

    for (Joueur j : m.getJoueurs()) {
      ((JoueurDefaut) j).addObserver(this);
    }

    pack();
    setVisible(true);
  }
 /** Restores the screen's display mode. */
 public void restoreScreen() {
   Window window = device.getFullScreenWindow();
   if (window != null) {
     window.dispose();
   }
   device.setFullScreenWindow(null);
 }
Example #5
0
 public static DisplayMode getDesktopDisplayMode() {
   GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
   GraphicsDevice device = genv.getDefaultScreenDevice();
   java.awt.DisplayMode mode = device.getDisplayMode();
   return new LwjglApplicationConfigurationDisplayMode(
       mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth());
 }
Example #6
0
  /**
   * Applies this geometry to a window. Makes sure that the window is not placed outside of the
   * coordinate range of all available screens.
   *
   * @param window the window
   */
  public void applySafe(Window window) {
    Point p = new Point(topLeft);

    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
      if (gd.getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
        virtualBounds = virtualBounds.union(gd.getDefaultConfiguration().getBounds());
      }
    }

    if (p.x < virtualBounds.x) {
      p.x = virtualBounds.x;
    } else if (p.x > virtualBounds.x + virtualBounds.width - extent.width) {
      p.x = virtualBounds.x + virtualBounds.width - extent.width;
    }

    if (p.y < virtualBounds.y) {
      p.y = virtualBounds.y;
    } else if (p.y > virtualBounds.y + virtualBounds.height - extent.height) {
      p.y = virtualBounds.y + virtualBounds.height - extent.height;
    }

    window.setLocation(p);
    window.setSize(extent);
  }
Example #7
0
 /** Recupera el modo de pantalla no completa */
 public void recuperarPantalla() {
   Window window = device.getFullScreenWindow();
   if (window != null) {
     window.dispose();
   }
   device.setFullScreenWindow(null);
 }
  public void beginExecution() {
    if (cam == null) {

      int numBuffers = 2;

      env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      device = env.getDefaultScreenDevice();
      // MultiBufferTest test = new MultiBufferTest(numBuffers, device);

      try {

        GraphicsConfiguration gc = device.getDefaultConfiguration();
        mainFrame = new Frame(gc);
        mainFrame.setUndecorated(true);
        mainFrame.setIgnoreRepaint(true);
        device.setFullScreenWindow(mainFrame);
        if (device.isDisplayChangeSupported()) {
          chooseBestDisplayMode(device);
        }
        mainFrame.createBufferStrategy(numBuffers);
        bufferStrategy = mainFrame.getBufferStrategy();

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Example #9
0
  private boolean enterFullScreenMode() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = ge.getScreenDevices();
    for (int i = 0; i < devices.length; i++) {
      GraphicsDevice device = devices[i];
      if (device.isFullScreenSupported() && device.getFullScreenWindow() == null) {
        log.info("Switching to full screen mode.");

        frame.setVisible(false);

        try {
          device.setFullScreenWindow(frame);
        } catch (InternalError e) {
          log.error("Failed to switch to full screen exclusive mode.");
          e.printStackTrace();

          frame.setVisible(true);
          return false;
        }

        frame.dispose();
        frame.setUndecorated(true);
        frame.setVisible(true);
        frame.requestFocusInWindow();

        return true;
      }
    }

    log.warn("No screens available or full screen exclusive mode is unsupported on your platform.");

    postError("Full screen mode is not supported on your platform.");

    return false;
  }
Example #10
0
  public MafiaMainClass() {
    setLayout(card); // BorderLayout

    // add("WR",wr);
    add("LOG", login); // window창 위에 penal을 올린다
    setTitle("MAFIA GAME - LOGIN");
    setSize(1280, 985); // window 크기

    /*			// 창을 중앙에 띄운다.
    			Dimension screen=Toolkit.getDefaultToolkit().getScreenSize();
    			Dimension ex_size = this.getSize();

    			int xpos=(int)(screen.getWidth()/2 - this.getWidth()/2);
    			int ypos=(int)(screen.getHeight()/2 - this.getHeight()/2);

    			this.setLocation(xpos,ypos);
    */
    // 전체화면
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    setUndecorated(true);
    gd.setFullScreenWindow(this);

    setVisible(true); // window 보이기
    setResizable(false); // 화면크기 고정

    addMouseListener(this); // mouse움직임
  }
Example #11
0
 /**
  * Create possibly volatile scratch image for fast painting. A scratch image can become
  * invalidated, when this happens any actions involving it are ignored, and it needs to be
  * recreated. Use isScratchImageValid() to check this.
  */
 public static Image createScratchImage(int width, int height) {
   try {
     Image img =
         (Image)
             tryMethod(
                 output_comp,
                 "createVolatileImage",
                 new Object[] {new Integer(width), new Integer(height)});
     if (img == null) {
       // no such method -> create regular image
       return output_comp.createImage(width, height);
     }
     // if (img.validate(output_comp.getGraphicsConfiguration())
     // == VolatileImage.IMAGE_INCOMPATIBLE) {
     GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gs = ge.getDefaultScreenDevice();
     GraphicsConfiguration gc = gs.getDefaultConfiguration();
     Integer valid = (Integer) tryMethod(img, "validate", new Object[] {gc});
     // output_comp.getGraphicsConfiguration() });
     if (valid.intValue() == 2) { // I checked, IMAGE_INCOMPATIBLE=2
       // Hmm, somehow it didn't work. Create regular image.
       return output_comp.createImage(width, height);
     }
     return img;
   } catch (java.security.AccessControlException e) {
     // we're not allowed to do this (we're probably an applet)
     return output_comp.createImage(width, height);
   }
 }
Example #12
0
  /**
   * From https://java3d.dev.java.net/issues/show_bug.cgi?id=89 Finds the preferred <code>
   * GraphicsConfiguration</code> object for the system. This object can then be used to create the
   * Canvas3D object for this system.
   *
   * @param window the window in which the Canvas3D will reside
   * @return The best <code>GraphicsConfiguration</code> object for the system.
   */
  private static GraphicsConfiguration getPreferredConfiguration(Window window) {
    if (window == null) return SimpleUniverse.getPreferredConfiguration();
    GraphicsDevice device = window.getGraphicsConfiguration().getDevice();
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    String stereo;

    // Check if the user has set the Java 3D stereo option.
    // Getting the system properties causes appletviewer to fail with a
    //  security exception without a try/catch.

    stereo =
        (String)
            java.security.AccessController.doPrivileged(
                new java.security.PrivilegedAction() {
                  public Object run() {
                    return System.getProperty("j3d.stereo");
                  }
                });

    // update template based on properties.
    if (stereo != null) {
      if (stereo.equals("REQUIRED")) template.setStereo(GraphicsConfigTemplate.REQUIRED);
      else if (stereo.equals("PREFERRED")) template.setStereo(GraphicsConfigTemplate.PREFERRED);
    }
    // Return the GraphicsConfiguration that best fits our needs.
    return device.getBestConfiguration(template);
  }
Example #13
0
  public synchronized void toggleFullScreen() {
    if (inFullScreen) {
      this.dispose();
      gd.setFullScreenWindow(null);
      canvas.setSize(NES_HEIGHT * screenScaleFactor, NES_WIDTH * screenScaleFactor);
      this.setUndecorated(false);
      this.setVisible(true);
      inFullScreen = false;
      buildMenus();
      // nes.resume();
    } else {
      setJMenuBar(null);
      gd = getGraphicsConfiguration().getDevice();
      if (!gd.isFullScreenSupported()) {
        // then fullscreen will give a window the size of the screen instead
        messageBox("Fullscreen is not supported by your OS or version of Java.");
      }
      this.dispose();
      this.setUndecorated(true);

      gd.setFullScreenWindow(this);
      this.setVisible(true);

      inFullScreen = true;
    }
  }
  public int getScreenHeight() {
    //        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    int height = gd.getDisplayMode().getHeight();
    return height;
  }
Example #15
0
 // get out of full screen
 public void restoreScreen() {
   Window w = vc.getFullScreenWindow();
   if (w != null) {
     w.dispose();
   }
   vc.setFullScreenWindow(null);
 }
Example #16
0
  /**
   * ZombieFrame's constructor.
   *
   * @param contents Optional JPanel(s) to add to content pane. Arguments > 0 are ignored.
   */
  public ZombieFrame(JPanel... contents) {
    super("ZombieHouse");

    // Request keyboard focus for the frame.
    setFocusable(true);
    requestFocusInWindow();
    requestFocus();

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setUndecorated(true);
    setResizable(false);
    setBackground(Color.BLACK);

    // The content pane. An optional JPanel may be passed into the
    // constructor. It creates an empty pane with a black background if
    // one isn't provided.
    pane = getContentPane();
    pane.setBackground(Color.BLACK);
    pane.setFocusable(false);
    pane.setVisible(true);
    if (contents.length > 0) {
      pane.add(contents[0]);
    }

    keys = new ZombieKeyBinds((JComponent) pane);

    // Get the graphics device information.
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphics = environment.getDefaultScreenDevice();

    pack();

    // Go full screen, if supported.
    if (graphics.isFullScreenSupported()) {
      try {
        graphics.setFullScreenWindow(this);
        // Having gone full screen, retrieve the display size.
        // size = Toolkit.getDefaultToolkit().getScreenSize();

        // This double-switching of setVisible is to fix a bug with
        // full-screen-exclusive mode on OS X. Versions 10.8 and later
        // don't send keyboard events properly without it.
        if (System.getProperty("os.name").contains("OS X")) {
          setVisible(false);
        }
      } catch (HeadlessException ex) {
        System.err.println(
            "Error: primary display not set or found. "
                + "Your experience of life may be suboptimal.");
        ex.printStackTrace();
      }
    } else {
      // If full-screen-exclusive mode isn't supported, switch to
      // maximized window mode.
      System.err.println("Full-screen-exclusive mode not supported.");
      setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    setVisible(true);
  }
Example #17
0
  public static BufferedImage createEmptyImage(final int w, final int h) {

    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final BufferedImage image = gc.createCompatibleImage(w, h, Transparency.BITMASK);
    return image;
  }
  public int getScreenWidth() {
    //         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    //        double width = screenSize.getWidth();
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

    int width = gd.getDisplayMode().getWidth();
    return width;
  }
  // TODO not used
  private void showNotification() {
    final WebDialog dialog = new WebDialog();
    dialog.setUndecorated(true);
    dialog.setBackground(Color.BLACK);
    dialog.setBackground(StyleConstants.transparent);

    WebNotificationPopup popup = new WebNotificationPopup(PopupStyle.dark);
    popup.setIcon(Utils.getIcon("kontalk_small.png"));
    popup.setMargin(View.MARGIN_DEFAULT);
    popup.setDisplayTime(6000);
    popup.addNotificationListener(
        new NotificationListener() {
          @Override
          public void optionSelected(NotificationOption option) {}

          @Override
          public void accepted() {}

          @Override
          public void closed() {
            dialog.dispose();
          }
        });

    // content
    WebPanel panel = new WebPanel();
    panel.setMargin(View.MARGIN_DEFAULT);
    panel.setOpaque(false);
    WebLabel title = new WebLabel("A new Message!");
    title.setFontSize(View.FONT_SIZE_BIG);
    title.setForeground(Color.WHITE);
    panel.add(title, BorderLayout.NORTH);
    String text = "this is some message, and some longer text was added";
    WebLabel message = new WebLabel(text);
    message.setForeground(Color.WHITE);
    panel.add(message, BorderLayout.CENTER);
    popup.setContent(panel);

    // popup.packPopup();
    dialog.setSize(popup.getPreferredSize());

    // set position on screen
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice gd = ge.getDefaultScreenDevice();
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    Rectangle screenBounds = gc.getBounds();
    // get height of the task bar
    // doesn't work on all environments
    // Insets toolHeight = toolkit.getScreenInsets(popup.getGraphicsConfiguration());
    int toolHeight = 40;
    dialog.setLocation(
        screenBounds.width - dialog.getWidth() - 10,
        screenBounds.height - toolHeight - dialog.getHeight());

    dialog.setVisible(true);
    NotificationManager.showNotification(dialog, popup);
  }
  /**
   * Create the window, asking for which screen to use if there are multiple monitors and either
   * forcechoice is true, or the user hasn't already picked a screen.
   *
   * @param part the JComponent to display
   * @param forcechoice false if user shouldn't be asked twice which of several monitors to use.
   */
  private void init(JComponent part, boolean forcechoice) {

    if (forcechoice) {

      defaultScreen = null;
    }

    screen = null;

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    GraphicsDevice screens[] = ge.getScreenDevices();

    if (defaultScreen != null) {

      for (int i = 0; i < screens.length; i++) {

        if (screens[i] == defaultScreen) {

          screen = defaultScreen;
        }
      }
    }

    if (screens.length == 1) {

      screen = screens[0];
    }

    if (screen == null) {

      screen = pickScreen(screens);
    }

    if (dead) {

      return;
    }

    defaultScreen = screen;

    DisplayMode dm = screen.getDisplayMode();

    GraphicsConfiguration gc = screen.getDefaultConfiguration();

    jf = new JFrame(gc);

    jf.setUndecorated(true);

    jf.setBounds(gc.getBounds());

    jf.getContentPane().add(part);

    jf.setVisible(true);

    screen.setFullScreenWindow(jf);
  }
Example #21
0
  /**
   * Creates a device compatible BufferedImage
   *
   * @param width the width in pixels
   * @param height the height in pixels
   */
  public static BufferedImage getDeviceCompatibleImage(int width, int height) {

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screenDevice = graphicsEnvironment.getDefaultScreenDevice();
    GraphicsConfiguration graphicConfiguration = screenDevice.getDefaultConfiguration();
    BufferedImage image = graphicConfiguration.createCompatibleImage(width, height);

    return image;
  }
 private static GraphicsDevice getScreen(JFrame window) {
   for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
     if (gd.getDefaultConfiguration().getBounds().contains(window.getLocationOnScreen()))
       return gd;
   }
   System.err.println(
       window + " does not appear to be on any screen; fullscreening onto default screen");
   return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
 }
Example #23
0
  public ChartingLogger() {
    frame = new LogChartFrame(new LoggerComms());
    //        frame = new LogChartFrame(new SocketComms());
    frame.pack();
    // restore previous window state, size, location if saved
    String[] stateItems =
        ConfigurationManager.getConfigItem(ConfigurationManager.CONFIG_WINDOWSTATE, "none")
            .split(",");

    // Toolkit.getDefaultToolkit().getScreenSize() doesn't work for multi monitor setups
    Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    Dimension frameSize = frame.getSize();
    if (stateItems[0].equals("none") || stateItems.length < 5) {

      frame.setLocation(center.x - frameSize.width / 2, center.y - frameSize.height / 2);
    } else {
      int x = Integer.parseInt(stateItems[0]);
      int y = Integer.parseInt(stateItems[1]);
      int width = Integer.parseInt(stateItems[2]);
      int height = Integer.parseInt(stateItems[3]);
      frame.setBounds(x, y, width, height);

      //  check bounds of saved NCL window and move within current device context if out of bounds
      boolean inSceenArea = false;
      for (GraphicsDevice gd :
          GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
          if (graphicsConfiguration.getBounds().outcode(x, y) == 0
              || graphicsConfiguration.getBounds().outcode(x + width, y + height) == 0) {
            inSceenArea = true;
          }
        }
      }
      if (!inSceenArea) {
        frame.setLocation(center.x - frameSize.width / 2, center.y - frameSize.height / 2);
      }
      // maximize if flagged
      if (stateItems[4].equals("Max")) frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(myWindowListener);
    frame.addComponentListener(wsl);

    // frame.setIconImage(Toolkit.getDefaultToolkit().getImage("graph.png"));
    Image appIcon = null;
    try {
      appIcon = new ImageIcon(getClass().getResource("graph.png")).getImage();
    } catch (Exception e) {
      appIcon = frame.getIconImage();
    }

    frame.setIconImage(appIcon);
    //        frame.pack();
    frame.setVisible(true);
    frame.requestFocus();
  }
 /**
  * Retrieves transparent image of specified dimension.
  *
  * @param width Image width.
  * @param height Image height.
  * @return Transparent image of specified dimension.
  */
 public static BufferedImage getBlankImage(int width, int height) {
   if (UIUtil.isRetina()) {
     return new JBHiDPIScaledImage(width, height, BufferedImage.TYPE_INT_ARGB);
   } else {
     GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice d = e.getDefaultScreenDevice();
     GraphicsConfiguration c = d.getDefaultConfiguration();
     return c.createCompatibleImage(width, height, Transparency.TRANSLUCENT);
   }
 }
Example #25
0
 /**
  * Get the full screen size recognizing multiple monitor.
  *
  * @return full screen size
  */
 public static Dimension getFullScreenSize() {
   Rectangle2D result = new Rectangle2D.Double();
   GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment();
   for (GraphicsDevice gd : localGE.getScreenDevices()) {
     for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) {
       Rectangle2D.union(result, graphicsConfiguration.getBounds(), result);
     }
   }
   return new Dimension((int) result.getWidth(), (int) result.getHeight());
 }
Example #26
0
 /**
  * Esta funcion recibe un modo y lo pone si es posible.
  *
  * @param dm Modo nuevo.
  */
 public void cambiarModo(DisplayMode dm) {
   try {
     if (device.isDisplayChangeSupported()) {
       device.setFullScreenWindow(getFullScreenWindow());
       device.setDisplayMode(dm);
     } else System.out.println("No se permite el cambio de resolucion");
   } catch (IllegalArgumentException ex) {
     System.out.println("Error de argumentos... No se ha podido poner a pantalla completa. ");
   }
 }
Example #27
0
 /** 将鼠标居中 */
 public void mouseCenter() {
   try {
     GraphicsDevice device =
         GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
     DisplayMode mode = device.getDisplayMode();
     this.mouseX = this.lastMouseX = (mode.getWidth() / 2) - 10;
     this.mouseY = this.lastMouseY = (mode.getHeight() / 2) - 10;
     LSystem.RO_BOT.mouseMove(this.mouseX, this.mouseY);
   } catch (Exception e) {
   }
 }
Example #28
0
  public static void main(String[] args) {
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice displayDevice = environment.getDefaultScreenDevice();

    frame = new Frame(displayDevice.getDefaultConfiguration());
    frame.setBackground(new Color(0xCC, 0xCC, 0xCC));
    frame.setTitle("TestBug735Inv0AppletAWT");

    try {
      Class<?> c =
          Thread.currentThread()
              .getContextClassLoader()
              .loadClass(Bug735Inv0AppletAWT.class.getName());
      applet = (Bug735Inv0AppletAWT) c.newInstance();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    frame.setLayout(null);
    frame.add(applet);
    frame.pack();
    frame.setResizable(false);

    applet.init();

    Insets insets = frame.getInsets();
    int windowW = applet.width + insets.left + insets.right;
    int windowH = applet.height + insets.top + insets.bottom;
    frame.setSize(windowW, windowH);

    Rectangle screenRect = displayDevice.getDefaultConfiguration().getBounds();
    frame.setLocation(
        screenRect.x + (screenRect.width - applet.width) / 2,
        screenRect.y + (screenRect.height - applet.height) / 2);

    int usableWindowH = windowH - insets.top - insets.bottom;
    applet.setBounds(
        (windowW - applet.width) / 2,
        insets.top + (usableWindowH - applet.height) / 2,
        applet.width,
        applet.height);

    // This allows to close the frame.
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });

    applet.initGL();
    frame.setVisible(true);
    applet.start();
  }
Example #29
0
 public void toggleToFullscreen() {
   GraphicsDevice device =
       GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
   DisplayMode[] modes = device.getDisplayModes();
   int i = 0; // note: there are usually several, let's pick the first
   settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
   settings.setFrequency(modes[i].getRefreshRate());
   settings.setDepthBits(modes[i].getBitDepth());
   settings.setFullscreen(device.isFullScreenSupported());
   restart();
 }
Example #30
0
 public static WGLGraphicsConfig getGC(WComponentPeer peer) {
   if (peer != null) {
     return (WGLGraphicsConfig) peer.getGraphicsConfiguration();
   } else {
     // REMIND: this should rarely (never?) happen, but what if
     //         default config is not WGL?
     GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
     GraphicsDevice gd = env.getDefaultScreenDevice();
     return (WGLGraphicsConfig) gd.getDefaultConfiguration();
   }
 }