I am attempting to load an 3 icon image but my code doesn't do so:
package com.proxy;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class ImageIconProxy extends ImageIcon implements Runnable{
static final ImageIcon ONE = new ImageIcon("/IFDesign/images/green.jpg");
static final ImageIcon TWO = new ImageIcon("/IFDesign/images/yellow.jpg");
ImageIcon CURRENT = ONE;
protected String fileName;
protected JFrame callBackFrame;
public ImageIconProxy(String fileName){
super(ONE.getImage());
this.fileName = fileName;
}
public void load(JFrame callBackFrame){
this.callBackFrame = callBackFrame;
CURRENT = TWO;
callBackFrame.repaint();
new Thread(this).start();
}
public void run(){
CURRENT = new ImageIcon(fileName);
callBackFrame.pack();
}
public int getIconWidth() {
return CURRENT.getIconWidth();
}
public int getIconHeight(){
return CURRENT.getIconHeight();
}
public synchronized void paintIcon(Component c, Graphics g, int x, int y){
CURRENT.paintIcon(c, g, x, y);
}
}
package com.proxy;
import java.awt.Graphics;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class JF extends JFrame {
protected static JF j;
protected static ImageIconProxy ip;
public JF(){
this.setTitle("TEST");
this.setSize(400,400);
}
public void paint(Graphics g){
super.paint(g);
ip.paintIcon(this, g, 100, 100);
}
public static void main(String[] args){
j = new JF();
ip = new ImageIconProxy("/IFDesign/images/blue.jpg");
ip.load(j);
j.setVisible(true);
}
}
Did I miss something? Your help is kindly appreciated.
Thank You.