title: Background Color in Java Graphics 2D is always black color
body: <p><strong>*I'm trying to print something but with a background in Pink Color and Text in White color. But the text color does change but screen is always in black color. *</strong></p>
  
  <pre><code>import java.awt.*;
  import javax.swing.JFrame;
  
  public class Screen {
  private GraphicsDevice vc;
  
  public Screen(){
      GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
  
      vc = env.getDefaultScreenDevice();
  }
  
  public void setFullScreen(DisplayMode dm, JFrame window){
      window.setUndecorated(true);
      window.setResizable(false);
      vc.setFullScreenWindow(window);
  
      if(dm!=null &amp;&amp; vc.isDisplayChangeSupported()){
          try{
              vc.setDisplayMode(dm);
          }
          catch(Exception ex){
  
          }
      }
  }
  public void restoreScreen(){
      Window w=vc.getFullScreenWindow();
      if(w!=null ){
          w.dispose();
      }
      vc.setFullScreenWindow(null);
  }
  
  
  }
  </code></pre>
  
  <p><strong>Now the main method :</strong></p>
  
  <pre><code>import javax.swing.JFrame;
  import java.awt.*;
  public class myGuiMain extends JFrame {
  public static void main(String arg[]){
  
  
      // Screen.java
  
      DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
      myGuiMain m = new myGuiMain();
      m.run(dm);
  }
  
  public void run(DisplayMode dm){
  
      setForeground(Color.WHITE);
      setBackground(Color.PINK);
      setFont(new Font("Arial",Font.PLAIN,25));
  
      Screen s = new Screen();
  
      try{
          s.setFullScreen(dm, this);
              try{
                  Thread.sleep(5000);
              }
              catch(Exception ex){
  
              }
          }finally{
              s.restoreScreen();
      }
  
  }
  
  public void paint(Graphics g){
      g.drawString("This is gonna be awesome",200,200);
  
  }
  }
  </code></pre>
  
  <p>RESULT:</p>
  
  <p><img src="https://i.stack.imgur.com/m3BPB.png" alt="enter image description here"></p>
  
  <p><strong>I have been searching on internet but end up with nothing. If anyone can resolve this issue, Thanks in advance.</strong></p>