Tue Nov 11, 2008 7:39 pm
import java.awt.*;
import java.awt.image.BufferStrategy;
public class ShowFullScreen {
private static int counter = 0;
private static final int size = 40;
private static DisplayMode displayMode[] = new DisplayMode[] {
new DisplayMode(640, 480, 32, 0), new DisplayMode(640, 480, 16, 0),
new DisplayMode(640, 480, 8, 0) };
private static DisplayMode getBestDisplayMode(GraphicsDevice device) {
for (int z = 0, n = displayMode.length; z < n; z++) {
DisplayMode[] displayMode = device.getDisplayModes();
for (int j = 0, k = displayMode.length; j < k; j++) {
if (displayMode[j].getWidth() == displayMode[z].getWidth()
&& displayMode[j].getHeight() ==displayMode[z].getHeight()
&& displayMode[j].getBitDepth(==displayMode[z].getBitDepth()){
return displayMode[z];
}
}
}
return null;
}
public static void main(String args[]) {
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
DisplayMode dm = gd.getDisplayMode();
try {
Frame f = new Frame("Show full screen");
gd.setFullScreenWindow(f);
if (gd.isDisplayChangeSupported()) {
gd.setDisplayMode(getBestDisplayMode(gd));
}
f.createBufferStrategy(5);
Rectangle rect = f.getBounds();
BufferStrategy bs = f.getBufferStrategy();
while (!done()) {
Graphics g = null;
try {
g = bs.getDrawGraphics();
if ((counter <= 5)) {
g.setColor(Color.white);
g.fillRect(0, 0, 650,550);
}
g.setColor(Color.red);
g.drawLine(counter, counter * 5, rect.width,
rect.height);
bs.show();
} finally {
if (g != null) {
g.dispose();
}
}
try {
Thread.sleep(150);
} catch (Exception e) {
}
}
} finally {}
System.exit(0);
}
private static boolean done() {
return (counter++ == size);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.