Advertisement
zachdyer

Java: Full Screen Mode

May 27th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. //Screen Class
  2. import java.awt.*;
  3. import javax.swing.JFrame;
  4.  
  5. public class Screen {
  6.     private GraphicsDevice vc;
  7.    
  8.     public Screen(){
  9.         GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  10.         vc = env.getDefaultScreenDevice();
  11.     }
  12.     public void setFullScreen(DisplayMode dm, JFrame window){
  13.         window.setUndecorated(true);
  14.         window.setResizable(false);
  15.         vc.setFullScreenWindow(window);
  16.        
  17.         if(dm != null && vc.isDisplayChangeSupported()){
  18.             try{
  19.                 vc.setDisplayMode(dm);
  20.             }catch(Exception ex){
  21.                
  22.             }
  23.         }
  24.     }
  25.    
  26.     public Window getFullScreenWindow(){
  27.         return vc.getFullScreenWindow();
  28.     }
  29.     public void restoreScreen(){
  30.         Window w = vc.getFullScreenWindow();
  31.         if(w != null){
  32.             w.dispose();
  33.         }
  34.         vc.setFullScreenWindow(null);
  35.     }
  36. }
  37.  
  38. //Main Class
  39. import java.awt.*;
  40. import javax.swing.JFrame;
  41.  
  42. public class Java extends JFrame {
  43.  
  44.     public static void main(String args[]){
  45.         DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
  46.         Java j = new Java();
  47.         j.run(dm);
  48.     }
  49.     public void run(DisplayMode dm){
  50.         setBackground(Color.black);
  51.         setForeground(Color.white);
  52.         setFont(new Font("Arial", Font.PLAIN, 24));
  53.        
  54.         Screen s = new Screen();
  55.         try{
  56.             s.setFullScreen(dm, this);
  57.             try{
  58.                 Thread.sleep(5000);
  59.             }catch(Exception ex){}
  60.         }finally{
  61.             s.restoreScreen();
  62.         }
  63.     }
  64.    
  65.     public void paint(Graphics g){
  66.         g.drawString("This is gonna be awesome!", 200, 200);
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement