java扩展ImageIcon类并保持兼容性
我有类表情,它扩展了ImageIcon
JLabel label = new JLabel("", emoticon); // emoticon is from class Emoticon
我不能这样做,因为JLabel正在寻找ImageIcon,而不是Emoticon。我能轻松解决这个问题吗
我已经扩展了ImageIcon,但我不确定是否应该这样做
public class Emoticon extends ImageIcon {
private static final long serialVersionUID = 1L;
Emoticon(String Path, String desc) {
super(Path, desc);
}
Emoticon(Image image) {
super(image);
}
public Emoticon getScaled(int width, int height) {
Image image= this.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
Emoticon ret = new Emoticon(image);
return ret;
}
}
我稍后会扩展它
如何使表情符号与JLabel兼容
# 1 楼答案
我犯了个错误
应该是
谢谢,我是汤姆·G