Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

setBackground()

843807Aug 22 2010 — edited Aug 22 2010
Hi,
Could anybody help with this problem which involves the setBackground() the problem is is that the screen should be Pink and it just keeps showing Black and it doesnt matter what color I set the seBackground to? it just shows black.
package javaapplication1;

import java.awt.*;

import javax.swing.JFrame;

public class Main extends JFrame
{
   public static void main(String []args)
   {


         DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
         Main b = new Main();
         b.run(dm);
      }

   /* instance methods */
   public void run(DisplayMode dm)
   {
      
      setBackground(Color.PINK);

      setForeground(Color.BLUE);

      setFont(new Font("Arial",Font.PLAIN,24));

      Screen s = new Screen();
      try
      {
         s.setFullScreen(dm,this);
         try
         {
            Thread.sleep(5000);
         }
         catch(Exception ex){}
      }
      finally
      {
         s.restoreScreen();
      }
   }
   public void paint(Graphics g)
   {
      if (g instanceof Graphics2D)
      {
         Graphics2D g2 = (Graphics2D)g;
         g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      }
      g.drawString("Hello World",200,200);
   }

}
package javaapplication1;

import java.awt.*;

import javax.swing.JFrame;

public class Screen
{
	/* instance variables */
  private GraphicsDevice vc;
	/**
	 * Default constructor for objects of class Screen
	 */
  public Screen()
  {
      super();
      GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      vc = env.getDefaultScreenDevice();
  }


	/* instance methods */
   public void setFullScreen(DisplayMode dm, JFrame window)
   {
      window.setUndecorated(true);
      window.setResizable(false);
      vc.setFullScreenWindow(window);

      if(dm != null && vc.isDisplayChangeSupported())
      {
         try
         {
            vc.setDisplayMode(dm);
         }
         catch(Exception ex)
         {
         }
      }
   }

   public Window getFullScreen()
   {
      return vc.getFullScreenWindow();
   }

   public void restoreScreen()
   {
      Window w = vc.getFullScreenWindow();
      if(w != null)
      {
         w.dispose();
      }
      vc.setFullScreenWindow(null);
   }

}

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 19 2010
Added on Aug 22 2010
4 comments
1,028 views