Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 4:59 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: full Screen Graphics
PostPosted: Tue Nov 11, 2008 7:39 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

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


Attachments:
File comment: the output
fullScreen.gif
fullScreen.gif [ 2.83 KiB | Viewed 1627 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Splash Screen
 How to show full resolution image at clicking on thumnail
 My Header is Not Fitting to the Screen!
 multi screen pcs?
 Java Websphere Portal Developer Full-time position in IL
 Full Encription System (DES-AES,RSA and more)
 how to screen scrape or grab some parts of a website?
 Full scrollable table
 Full Phone Book System php and mysql
 java graphics

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team