This is my code which would create a window that would takeover my full screen and would have a background colour of blue and would print "Hello World" in black, but when I run this application my screen freezes and the text "Hello World" comes out and after 5 seconds the thread terminates, but background colour does not changes and the screen becomes like this! 

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import javax.swing.JFrame;

public class Screen {
   private GraphicsDevice graphic_card;

   public Screen() {
       GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
       graphic_card = environment.getDefaultScreenDevice();
   }

   public void set_full_screen(DisplayMode mode, JFrame window) {
       window.setUndecorated(true);
       window.setResizable(false);
       graphic_card.setFullScreenWindow(window);
       if ((mode != null) && (graphic_card.isDisplayChangeSupported())) {
           try {
               graphic_card.setDisplayMode(mode);
           } catch (Exception exception) {
               // No handling of exception
           }
       }
   }

   public Window getFullScreenWindow() {
       return graphic_card.getFullScreenWindow();
   }

   public void restore_screen() {
       Window window = graphic_card.getFullScreenWindow();
       if (window != null) {
           window.dispose();
       }
       graphic_card.setFullScreenWindow(null);
   }
}



import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;

public class Mayank extends JFrame {
   public static void main(String[] args) {
       DisplayMode display_mode = new DisplayMode(800, 600, 16, DisplayMode.REFRESH_RATE_UNKNOWN);
       Mayank mayank = new Mayank();
       mayank.run(display_mode);
   }

   public void run(DisplayMode display_mode) {
       setBackground(Color.BLUE);
       setForeground(Color.BLACK);
       setFont(new Font("Arial", Font.PLAIN, 24));
       Screen game_screen = new Screen();
       try {
           game_screen.set_full_screen(display_mode, this);
           try {
               Thread.sleep(5000);
           } catch (Exception exception) {
               // No handling of exception
           }
       } finally {
           game_screen.restore_screen();
       }
   }

   public void paint(Graphics g) {
       g.drawString("Hello World!!", 200, 200);
   }
}