import java.awt.*; import java.awt.event.*; /** * Create window and display TGA file image * @author Phil Gage */ public class Show extends Panel { Image img = null; // Image pixmap for graphics static Frame f; static String filename; /** * Method paint redraws window each time window is exposed. * Could draw simple graphics directly in this method. * This version saves graphics in image for fast redraw. * @param g graphics object */ public void paint (Graphics g) { // Initialize image only once if (img == null) { img = loadImage (); } // Refresh image using current window size g.drawImage (img, 0, 0, getWidth(), getHeight(), this); } /** * Method loadImage reads TGA file into image. * This version saves graphics in image for fast redraw. */ Image loadImage () { FrameBuffer fb = new FrameBuffer (); if (!fb.loadtga (filename)) { System.out.println ("Error reading file: " + filename); System.exit(0); } // Resize window to image size f.setSize (fb.width,fb.height); return fb.getImage (f); } /** * Main program for command line application. * Creates panel in frame and displays image. * @param argv command line argument strings */ public static void main (String[] argv) { System.out.println ("TGA file viewer by Phil Gage"); System.out.println ("Master's Thesis, Univ of Colo, 2002"); System.out.println ("Usage: java Show [filename]"); System.out.println ("Default filename is frame0.tga"); // Get TGA file name, use default if none if (argv.length == 0) filename = "frame0.tga"; else filename = argv[0]; // Create frame and app f = new Frame (filename); Show app = new Show (); // Add window close event handler f.addWindowListener (new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } }); // Put panel in frame f.add ("Center", app); f.setSize (320,200); f.show (); } }