public static void toFullScreen(
     JFrame window,
     GraphicsDevice gd,
     boolean tryAppleFullscreen,
     boolean tryExclusiveFullscreen) {
   if (appleEawtAvailable()
       && tryAppleFullscreen
       && appleOSVersion() >= 7
       && // lion and above
       javaVersion() >= 7) { // java 7 and above
     System.out.println("trying to apple fullscreen");
     enableAppleFullscreen(window);
     doAppleFullscreen(window);
   } else if (appleEawtAvailable()
       && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL
       tryExclusiveFullscreen
       && gd.isFullScreenSupported()) {
     if (javaVersion() >= 7) setAutoRequestFocus(window, true);
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     // window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     gd.setFullScreenWindow(window);
     window.toFront();
     Rectangle r = gd.getDefaultConfiguration().getBounds();
     window.setBounds(r);
     // window.pack();
   } else { // Windows and Linux TODO: test this
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     window.setUndecorated(true);
     window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight());
     window.setLocation(0, 0);
     window.setExtendedState(JFrame.MAXIMIZED_BOTH);
     window.toFront();
   }
   window.pack();
   window.setVisible(true);
 }
Пример #2
0
  @Override
  public final synchronized void render() {
    final Graphics graphics = buffer.getDrawGraphics();
    if (smoothScale) {
      ((Graphics2D) graphics)
          .setRenderingHint(
              RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    }
    if (inFullScreen) {
      graphics.setColor(Color.BLACK);
      DisplayMode dm = gd.getDisplayMode();
      int scrnheight = dm.getHeight();
      int scrnwidth = dm.getWidth();
      // don't ask why this needs to be done every frame,
      // but it does b/c the canvas keeps resizing itself
      canvas.setSize(scrnwidth, scrnheight);
      graphics.fillRect(0, 0, scrnwidth, scrnheight);
      if (PrefsSingleton.get().getBoolean("maintainAspect", true)) {
        double scalefactor = getmaxscale(scrnwidth, scrnheight);
        int height = (int) (NES_HEIGHT * scalefactor);
        int width = (int) (256 * scalefactor * 1.1666667);
        graphics.drawImage(
            frame,
            ((scrnwidth / 2) - (width / 2)),
            ((scrnheight / 2) - (height / 2)),
            width,
            height,
            null);
      } else {
        graphics.drawImage(frame, 0, 0, scrnwidth, scrnheight, null);
      }
      graphics.setColor(Color.DARK_GRAY);
      graphics.drawString(this.getTitle(), 16, 16);

    } else {
      graphics.drawImage(
          frame, 0, 0, NES_WIDTH * screenScaleFactor, NES_HEIGHT * screenScaleFactor, null);
    }

    graphics.dispose();
    buffer.show();
  }
Пример #3
0
  /** creates the lobby. */
  public ClientLobby(User u) {
    this.user = u;

    /*
     * Get Infos about the screen
     * */
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice screen = ge.getDefaultScreenDevice();
    DisplayMode disp = screen.getDisplayMode();
    screenX = disp.getWidth();
    screenY = disp.getHeight();

    JPanel bg = createBackground();

    /*
     * Set up lobby / inputs
     * */
    lobbyParent = new JFrame("SwissDefcon Lobby");
    lobbyParent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    lobbyParent.setSize(iLobbyX, iLobbyY);
    lobbyParent.setResizable(false);
    lobbyParent.setLocation(screenX / 2 - iLobbyX / 2, screenY / 2 - iLobbyY / 2);
    lobbyParent.setContentPane(bg);

    s = new SelectServer(user);
    s.addServerSelectedListener(
        new ServerSelectedListener() {
          public void serverSelected(final ServerSelectedEvent ev) {
            ServerAddress server = ev.getServer();
            String desiredNick = ev.getUsername();
            try {
              Log.InformationLog(
                  "-->Connecting to "
                      + ev.getServer().getServerName()
                      + "("
                      + server.getAddress().getHostAddress()
                      + ") as "
                      + ev.getUsername()
                      + "(desired Username)");

              // stop discovery
              s.stopSearch();
              s.setVisible(false);

              // make Connection
              socket = new Clientsocket(server);
              // JOptionPane.showMessageDialog(lobbyParent, "Verbunden mit Server");

              l = new InnerLobby(socket, user);
              lobbyParent.add(l);

              // request nick
              socket.sendData(Protocol.CON_NICK.str() + desiredNick);

              // TODO Game Listener to start game here.

              socket.addInfoEventListener(
                  new InfoEventListener() {
                    @Override
                    public void received(final InfoEvent evt) {
                      if (evt.getId() == -1) {
                        Log.InformationLog("Connection to server broken, starting ServerSelect");
                        JOptionPane.showMessageDialog(
                            lobbyParent,
                            "Verbindungsunterbruch",
                            "Connection Error",
                            JOptionPane.ERROR_MESSAGE);
                        // TODO remove the game if it exists.
                        socket.disconnect();
                        lobbyParent.remove(l);
                        lobbyParent.validate();
                        lobbyParent.repaint();
                        s.setVisible(true);
                        s.startSearch();
                      }
                    }
                  });

            } catch (Exception e) {
              // e.printStackTrace();
              Log.WarningLog("-->connection broken, could not connect");
              JOptionPane.showMessageDialog(
                  lobbyParent,
                  "Konnte nicht mit Server verbinden: ",
                  "Connection Error",
                  JOptionPane.ERROR_MESSAGE);
              if (socket != null) {
                socket.disconnect();
              }
              s.setVisible(true);
              s.startSearch();
            }
          }
        });
    lobbyParent.add(s);
    Log.InformationLog("you can now select a server");

    lobbyParent.setVisible(true);
  }