Switch to full style
General Java code examples
Post a reply

full Screen Graphics

Tue Nov 11, 2008 7:39 pm

full Screen Graphics in java
Code:
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(640480320), new DisplayMode(640480160),
      new 
DisplayMode(64048080) };

  private static 
DisplayMode getBestDisplayMode(GraphicsDevice device) {
    for (
int z 0displayMode.lengthnz++) {
      
DisplayMode[] displayMode device.getDisplayModes();
      for (
int j 0displayMode.lengthkj++) {
        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 {
          
bs.getDrawGraphics();
          if ((
counter <= 5)) { 
            
g.setColor(Color.white);
            
g.fillRect(00650,550);
          }
          
g.setColor(Color.red);
          
g.drawLine(countercounter 5rect.width,
            
rect.height);
    
bs.show();
        } 
finally {
          if (
!= null) {
            
g.dispose();
          }
        }
        try {
          
Thread.sleep(150);
        } catch (
Exception e) {
        }
      }
    } 
finally {}
    
System.exit(0);
  }
 private static 
boolean done() {
    return (
counter++ == size);
  }



Attachments
fullScreen.gif
the output
fullScreen.gif (2.83 KiB) Viewed 5915 times

Post a reply
  Related Posts  to : full Screen Graphics
 Full Screen graphics (Lesson 2).     -  
 Splash Screen     -  
 Screen Capture and multicast     -  
 My Header is Not Fitting to the Screen!     -  
 Graphics commands list in C++     -  
 MacBook Pro Turned Into a Blue Screen     -  
 Flashing Graphics animations with threads     -  
 double buffering-applet animates graphics     -  
 how to screen scrape or grab some parts of a website?     -  
 getting a full line input     -  

Topic Tags

Java Graphics