import java.awt.*;
import java.applet.*;
import java.awt.event.*; 

public class Demo2Image extends Applet implements ActionListener {
	Button btnMove; 
	private int imageLeft = 10;	//stores location of left side of image
	Image myImage; //Image object which will be drawn
		
	public void init() {  	
		setLayout(null); 
        btnMove = new Button("Move Image"); 
		btnMove.setBounds(40,100,300,40);  
  		add(btnMove); 		
  		btnMove.addActionListener(this);		
	}

	public void paint(Graphics g) {  
		myImage = getImage(getCodeBase(), "box.gif" ); //loads the image
		//box.gif MUST BE IN SAME FOLDER AS THE CLASS FILE (not the .java file)
		g.drawImage(myImage,imageLeft,10,this); 
		//draws the image at (x = imageLeft, y = 10)
		g.drawLine(0,0,imageLeft, 10); 
		//draws a line from origin to corner of box image
	}
	
	public void actionPerformed(ActionEvent event){   	
  		if (event.getSource() == btnMove)  {
  			imageLeft = imageLeft + 10; //increments left side of image
  			repaint();	
		}
	}
}

