001 package org.rakeshv.applications;
002
003 import java.awt.*;
004 import java.awt.event.*;
005 import java.awt.image.*;
006 import javax.imageio.*;
007 import java.io.*;
008
009 /**
010 * <p>A simple programme that tests the new full screen support and
011 * the new ImageIO classes introduced in J2SE 1.4.</p>
012 */
013 public class FullScreen extends Window
014 {
015 private BufferedImage pic;
016
017 /**
018 * The <code>main method</code> checks to make sure that the current
019 * display supports <code>full screen</code> display. If <code>full
020 * screen</code> display is supported, it attempts to load the
021 * image specified on the <code>command line</code>, and renders
022 * it onto the <code>full screen window</code>.
023 *
024 * @param args - The command line arguments array
025 */
026 public static void main( String[] args )
027 {
028 if ( args.length != 1 )
029 {
030 System.out.println( "Usage: java -jar fullscreen.jar <picture>" );
031 System.exit( 1 );
032 }
033
034 GraphicsEnvironment ge =
035 GraphicsEnvironment.getLocalGraphicsEnvironment();
036
037 GraphicsDevice screen = ge.getDefaultScreenDevice();
038
039 if ( ! screen.isFullScreenSupported() )
040 {
041 System.out.println( "Full screen mode not supported." );
042 }
043
044 try
045 {
046 BufferedImage loadedPic = ImageIO.read( new File( args[ 0 ] ) );
047 screen.setFullScreenWindow( new FullScreen( loadedPic ) );
048 }
049 catch ( Exception ex )
050 {
051 System.err.println( ex.getMessage() );
052 }
053 }
054
055 /**
056 * The <code>constructor</code> just adds a <code>MouseListener</code>
057 * that closes the application upon a <code>mouse click event</code>.
058 *
059 * @param pic - The image to render into the window.
060 */
061 public FullScreen( BufferedImage pic )
062 {
063 super( new Frame() );
064
065 this.pic = pic;
066
067 addMouseListener( new MouseAdapter() {
068 public void mouseClicked( MouseEvent me )
069 {
070 System.exit( 0 );
071 }
072 });
073 }
074
075 /**
076 * The <code>over-loaded paint method</code>. This method takes
077 * care of actually drawing the image onto the window.
078 *
079 * @param g - The graphics context to use.
080 */
081 public void paint( Graphics g )
082 {
083 g.drawImage( pic, 0, 0, getWidth(), getHeight(), this );
084 }
085 }