Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nl.jorikoolstra.jLevel.Graphics;
- import java.awt.*;
- import javax.swing.JFrame;
- import java.awt.image.BufferStrategy;
- public class ScreenManager
- {
- private GraphicsDevice graphicsDevice;
- /**
- * Creates a screen manager for the default screen device.
- */
- public ScreenManager()
- {
- GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
- graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();
- }
- public void setFullScreen(DisplayMode displayMode, JFrame hwnd)
- {
- hwnd.setUndecorated(true);
- hwnd.setResizable(false);
- graphicsDevice.setFullScreenWindow(hwnd);
- if (displayMode != null && graphicsDevice.isDisplayChangeSupported())
- {
- try
- {
- graphicsDevice.setDisplayMode(displayMode);
- }
- catch (IllegalArgumentException ex)
- {
- System.exit(1);
- }
- }
- /* Create buffer strategy for the window */
- hwnd.createBufferStrategy(2);
- }
- public Window getFullScreenWindow()
- {
- return graphicsDevice.getFullScreenWindow();
- }
- public BufferStrategy getBufferStrategy()
- {
- return getFullScreenWindow().getBufferStrategy();
- }
- public Graphics2D getGraphics()
- {
- return (Graphics2D) getBufferStrategy().getDrawGraphics();
- }
- public int getWidth()
- {
- return getFullScreenWindow().getWidth();
- }
- public int getHeight()
- {
- return getFullScreenWindow().getHeight();
- }
- public void updateGraphicsDisplay()
- {
- BufferStrategy bufferStrategy = getBufferStrategy();
- if (!bufferStrategy.contentsLost())
- {
- bufferStrategy.show();
- }
- }
- public void restoreScreen()
- {
- Window hwnd = graphicsDevice.getFullScreenWindow();
- if (hwnd != null) hwnd.dispose();
- graphicsDevice.setFullScreenWindow(null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement