Hey guys, I'm working on a game, and I was trying to mirror the gif images inside the program so I wouldn't have to do it manually (And also so it wouldn't use twice as much space to store the mirrored gifs). Anyway, I Google'd it and found this answer, it works well in the code, when you set the imageIcon as the JLabel Icon, but when I try to modify it a little and paint the image to a component, it just disappears... Here's the code:
public class HelperClass {
public static void main(String[] args) {
JFrame f = new JFrame("Test");
final ImageIcon io = new MirrorImageIcon("test.gif");
final ImageIcon oi = new ImageIcon("test.gif");
final Component c = new Component() {
@Override
public void paint(Graphics g) {
super.paint(g);
io.paintIcon(this, g, 50, 50);
oi.paintIcon(this, g, 100, 50);
}
};
f.add(c);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,300);
f.setVisible(true);
}
}
class MirrorImageIcon extends ImageIcon {
public MirrorImageIcon(String filename) {
super(filename);
}
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D)g.create();
g2.translate(getIconWidth(), 0);
g2.scale(-1, 1);
super.paintIcon(c, g2, x, y);
}
}
The original Image shows up, but the mirrored one doesn't! What am I doing wrong?