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