ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.vci.client.ui.image;
 
import javax.swing.ImageIcon;
 
public class BundleImage {
 
private String path = "/resource/images/"; //the path of images's folder
    
    public BundleImage()
    {
    } 
    
    
    public String getPath() {
        return this.path;
    }
    
    /**
     * set the path of image's folder, or use the default
     * 
     * @param path
     */
    public void setPath(String path) {
        this.path = path;
    }
 
    /**
     * create a new ImageIcon and return it
     * 
     * @param fileName
     * @return
     */
    public ImageIcon createImageIcon(String fileName){
        ImageIcon icon = new ImageIcon("");
        if (fileName == null || fileName.length() == 0) {
            return icon;
        }
        if (path == null || path.length() == 0) {
            return icon;
        }
        try {
            icon = new ImageIcon(BundleImage.class.getResource(path + fileName));
        } catch (Exception e) {
        }
      return icon;
    }
    
    /**
     * create a new ImageIcon and return it
     * 
     * @param filePath
     * @return
     */
    public ImageIcon createImageIconByPath(String filePath){
        ImageIcon icon = new ImageIcon("");
        if (filePath == null || filePath.length() == 0) {
            return icon;
        }
 
        try {
            icon = new ImageIcon(BundleImage.class.getResource(filePath));
        } catch (Exception e) {
        }
      return icon;
    }
}