package utils; import java.awt.*; import java.awt.image.*; public class DynamicImage { private String filePath; private BufferedImage img; private Color bg, shadow; public DynamicImage(String filePath) { this.filePath = filePath; img = null; bg = shadow = null; } public DynamicImage(String filePath, Color bg, Color shadow) { this.filePath = filePath; img = null; this.bg = bg; this.shadow = shadow; } private void loadImg() { if(bg == null) img = Utils.loadImg(filePath); else img = Utils.loadTransImg(filePath, bg, shadow); } public int getHeight() { if(img == null) loadImg(); return img.getHeight(); } public int getWidth() { if(img == null) loadImg(); return img.getWidth(); } public void draw(Graphics g, int x, int y) { if(img == null) loadImg(); g.drawImage(img, x, y, null); } public void draw(Graphics g, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { if(img == null) loadImg(); g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } }