// Scott DeRuiter 3/27/03 // ShowImage.java // Shows an image. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ShowImage extends JApplet { private int xpos, ypos; private boolean click; private Image image; private DrawingArea canvas; public ShowImage ( ) { xpos = ypos = 0; click = false; } public void init ( ) { canvas = new DrawingArea ( ); setContentPane ( canvas ); canvas.setBackground( Color.darkGray ); image = getImage ( getDocumentBase ( ), "Halloween.jpg" ); WaitForImage ( this, image ); } public void WaitForImage ( JApplet component, Image image ) { MediaTracker tracker = new MediaTracker ( component ); try { tracker.addImage ( image, 0 ); tracker.waitForID ( 0 ); } catch ( InterruptedException e ) { e.printStackTrace ( ); } } class DrawingArea extends JPanel implements MouseListener { public DrawingArea ( ) { addMouseListener ( this ); } public void paintComponent ( Graphics g ) { boolean b; if ( !click ) super.paintComponent ( g ); else b = g.drawImage ( image, xpos, ypos, 270, 180, this ); click = false; } public void mousePressed ( MouseEvent e ) { click = true; xpos = e.getX ( ) - 135; ypos = e.getY ( ) - 90; repaint ( ); } public void mouseClicked ( MouseEvent e ) {} public void mouseReleased ( MouseEvent e ) {} public void mouseEntered ( MouseEvent e ) {} public void mouseExited ( MouseEvent e ) {} } }