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);
}
}