org/homelinux/largo/utils/ImgComponent.java
changeset 16 55b0d5006e7b
parent 14 f12f77aa13b2
equal deleted inserted replaced
15:d4b2b9a87d80 16:55b0d5006e7b
     6 import java.net.URL;
     6 import java.net.URL;
     7 
     7 
     8 import javax.swing.ImageIcon;
     8 import javax.swing.ImageIcon;
     9 
     9 
    10 public class ImgComponent extends Canvas {
    10 public class ImgComponent extends Canvas {
    11     static final long serialVersionUID = 1L;
    11 	static final long serialVersionUID = 1L;
    12     private Image img;
    12 	private Image img;
    13 
    13 
    14     public ImgComponent(String sFile) {
    14 	public ImgComponent(String sFile) {
    15         ClassLoader cl = getClass().getClassLoader();
    15 		ClassLoader cl = getClass().getClassLoader();
    16         URL url = cl.getResource(sFile);
    16 		URL url = cl.getResource(sFile);
    17         img = new ImageIcon(url).getImage();
    17 		img = new ImageIcon(url).getImage();
    18     }
    18 	}
    19 
    19 
    20     public Image getImage() {
    20 	public Image getImage() {
    21         return img;
    21 		return img;
    22     }
    22 	}
    23 
    23 
    24     public Dimension getPreferredSize() {
    24 	public Dimension getPreferredSize() {
    25         return new Dimension(img.getWidth(this), img.getHeight(this));
    25 		return new Dimension(img.getWidth(this), img.getHeight(this));
    26     }
    26 	}
    27 
    27 
    28     public Dimension getMinimumSize() {
    28 	public Dimension getMinimumSize() {
    29         return getPreferredSize();
    29 		return getPreferredSize();
    30     }
    30 	}
    31 }
    31 }