/** * This is a brief example of how to draw a .jpg image on a * javabook MainWindow. * * @author Jeff Ondich and Mike Tie * @version 3/10/03 */ import javabook.*; import java.awt.*; class ImageWindow extends MainWindow { Image theImage; public static void main( String[] args ) { ImageWindow w = new ImageWindow(); w.setVisible( true ); } public ImageWindow() { // Load the image file into an instance of the Image class. // Note that you need to specify the full path of the image file // (there are ways around this, but they are hard to make reliable). // I used Windows to develop this--thus the "c:/..." path. To find // out the path for your Linux account, log in and type "pwd" in the // terminal. theImage = Toolkit.getDefaultToolkit().getImage( "c:/windows/desktop/somepicture.jpg" ); // Now that you have the image loaded, you want to scale it to // be a particular size. This example scales the width to 200 pixels. // The -1 in the "height" parameter says "use the images inherent // aspect ratio." Thus, the result will look like the original image, // but 200 pixels wide. theImage = theImage.getScaledInstance( 200, -1, 0 ); } public void paint( Graphics g ) { g.drawImage( theImage, 100, 100, this ); } }