Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2013
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package nl.jorikoolstra.jLevel.Graphics;
  2.  
  3. import java.awt.*;
  4. import javax.swing.JFrame;
  5. import java.awt.image.BufferStrategy;
  6.  
  7.  
  8. public class ScreenManager
  9. {
  10.     private GraphicsDevice graphicsDevice;
  11.  
  12.  
  13.     /**
  14.     * Creates a screen manager for the default screen device.
  15.     */
  16.     public ScreenManager()
  17.     {
  18.         GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
  19.         graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
  20.     }
  21.  
  22.  
  23.     public void setFullScreen(DisplayMode displayMode, JFrame hwnd)
  24.     {
  25.         hwnd.setUndecorated(true);
  26.         hwnd.setResizable(false);
  27.  
  28.         graphicsDevice.setFullScreenWindow(hwnd);
  29.  
  30.         if (displayMode != null && graphicsDevice.isDisplayChangeSupported())
  31.         {
  32.             try
  33.             {
  34.                 graphicsDevice.setDisplayMode(displayMode);
  35.             }
  36.             catch (IllegalArgumentException ex)
  37.             {
  38.                 System.exit(1);
  39.             }
  40.         }
  41.  
  42.         /* Create buffer strategy for the window */
  43.         hwnd.createBufferStrategy(2);
  44.     }
  45.  
  46.     public Window getFullScreenWindow()
  47.     {
  48.         return graphicsDevice.getFullScreenWindow();
  49.     }
  50.  
  51.  
  52.     public BufferStrategy getBufferStrategy()
  53.     {
  54.         return getFullScreenWindow().getBufferStrategy();
  55.     }
  56.  
  57.  
  58.     public Graphics2D getGraphics()
  59.     {
  60.         return (Graphics2D) getBufferStrategy().getDrawGraphics();
  61.     }
  62.  
  63.  
  64.     public int getWidth()
  65.     {
  66.         return getFullScreenWindow().getWidth();
  67.     }
  68.  
  69.  
  70.     public int getHeight()
  71.     {
  72.         return getFullScreenWindow().getHeight();
  73.     }
  74.  
  75.     public void updateGraphicsDisplay()
  76.     {
  77.         BufferStrategy bufferStrategy = getBufferStrategy();
  78.         if (!bufferStrategy.contentsLost())
  79.         {
  80.             bufferStrategy.show();
  81.         }
  82.     }
  83.  
  84.  
  85.     public void restoreScreen()
  86.     {
  87.         Window hwnd = graphicsDevice.getFullScreenWindow();
  88.         if (hwnd != null) hwnd.dispose();
  89.         graphicsDevice.setFullScreenWindow(null);
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement