Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package me.Kenny.GUI_WINDOW_INITILIZATION;
  2.  
  3. public static void main(String[] args){
  4.  
  5. DisplayMode dm = new DisplayMode(1200,800,32, DisplayMode.REFRESH_RATE_UNKNOWN);
  6. Main m = new Main();
  7. m.run(dm);
  8.  
  9. }
  10.  
  11. public void run(DisplayMode dm1){
  12.  
  13. setBackground(Color.PINK);
  14. setForeground(Color.WHITE);
  15. setFont(new Font("Arial", Font.PLAIN, 24));
  16.  
  17. Screen s = new Screen();
  18.  
  19. try{
  20.  
  21. s.setFullScreen(dm1, this);
  22. try{
  23.  
  24. Thread.sleep(5000);
  25.  
  26. }catch(Exception e){}
  27.  
  28. }finally{
  29.  
  30. s.restoreScreen();
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37. public void paint(Graphics g){
  38.  
  39. g.drawString("This is gonna be awesome", 300, 300);
  40.  
  41.  
  42. }
  43.  
  44. package me.Kenny.GUI_WINDOW_INITILIZATION;
  45.  
  46. private GraphicsDevice vc;
  47.  
  48. public Screen(){
  49.  
  50. GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  51.  
  52. vc = env.getDefaultScreenDevice();
  53.  
  54. }
  55.  
  56. public void setFullScreen(DisplayMode dm, JFrame window){
  57.  
  58. window.setUndecorated(true);
  59. window.setResizable(false);
  60. vc.setFullScreenWindow(window);
  61.  
  62. if(dm != null && vc.isDisplayChangeSupported()){
  63.  
  64. try{
  65.  
  66. vc.setDisplayMode(dm);
  67. System.out.println("is in try");
  68.  
  69. }catch(IllegalArgumentException ex){
  70.  
  71. System.out.println("Unable to set Display mode");
  72.  
  73. }
  74.  
  75. }
  76.  
  77. }
  78.  
  79. public Window getFullScreenWindow(){
  80.  
  81. return vc.getFullScreenWindow();
  82. }
  83.  
  84.  
  85.  
  86. public void restoreScreen(){
  87.  
  88. Window w = vc.getFullScreenWindow();
  89.  
  90. if (w != null){
  91. w.dispose();
  92.  
  93. }
  94.  
  95. vc.setFullScreenWindow(null); //closes window
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement