import java.awt.*; import javax.swing.*; /* * * @author Owen Astrachan */ public class TapImage extends JPanel { final static int SIZE = 80; /** * @param name URL/filename of image * */ public TapImage(String name, int size) { myImage = ImageLoader.loadImage(this,name); myDim = new Dimension(size,size); mySize = size; } public TapImage(String name) { this(name,SIZE); } public Dimension getPreferredSize() { return myDim; } public Dimension getMinimumSize() { return myDim; } public void paintComponent(Graphics g) { super.paintComponent(g); // draw the image scaled int x = getBounds().x; int y = getBounds().y; g.drawImage(myImage,x,y, x+myDim.width, y+myDim.height, 0,0,myImage.getWidth(this),myImage.getHeight(this),this); } private Image myImage; private Dimension myDim; private int mySize; }