/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ File: GraphicsExampleFrame2WithLoadingImage.java Date: 12/30/2005 Author: mr. Hanley Purpose: Demonstrate how to load up an image using imageio @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/ import java.awt.*; import javax.swing.*; import javax.imageio.*; //Utilities for working with images import java.awt.image.*; import java.io.*; public class GraphicsExampleFrame2WithLoadingImage extends JFrame { BufferedImage image1; //This is an image variable BufferedImage img = new BufferedImage(500,400,BufferedImage.TYPE_INT_ARGB); int x = 8, y = 38; /***************************************************************** * public GraphicsExampleFrame2WithLoadingImage() * pre: * post: attempts to load image into variable image1 * *****************************************************************/ public GraphicsExampleFrame2WithLoadingImage() { try { image1 = ImageIO.read(new File("images/kipper.gif")); }catch(java.io.IOException e) { System.out.println(e); } } public void update(Graphics g) { paint(img.getGraphics()); g.drawImage(img,0,0,null); } public void paint(Graphics g) { g.fillRect(0,0,500,400); g.setColor(Color.red); g.fillOval(x, y, 20, 50); x += 10; //draw the image g.drawImage(image1,x+100,y+100,null); //Draw the image to the screen g.drawImage(img, 0, 0, null); //Pause try { Thread.sleep(100); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } //Invoke repaint repaint(); } }