Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Show Graphics on full Screen 
 

To display the graphics, we have used the class DisplayMode which provides the bit depth, height, width, and refresh rate of a GraphicsDevice.

 

Show Graphics on full Screen

                         

This section illustrates you how to show graphics on full screen.

To display the graphics, we have used the class DisplayMode which provides the bit depth, height, width, and refresh rate of a GraphicsDevice. The graphics devices are described by the class GraphicsDevice and contains the objects of  class GraphicsConfiguration and specify these objects into different configurations.

To organize the graphics on a window or canvas, we used the class BufferStrategy.  To returns the screen on which the graphics will displayed, the method getDefaultScreenDevice() is used and to return the current mode of graphics device, method getDisplayMode() is used.

To displays the full screen mode, the method setFullScreenWindow(f) is used.  If the graphics device supports the display changes, the method  isDisplayChangeSupported() returns true.

Then creates a new strategy with the number of buffers for multi-buffering specified  by the method createBufferStrategy(5). It is useful to render the performance. The getBufferStrategy() returns the BufferStrategy used by its component. If a BufferStrategy has not been created or disposed, it will return null.

 The method getDrawGraphics() of class BufferStrategy displays the graphics. 

Here is the code of ShowFullScreen.java

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

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c com diff vi value return opera id show if example unc values exam mode ws xor sh bot e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.