Icon 图标
ImageIcon() 类是Icon接口的一个实现类 用于加载指定的文件 通常 加载图片的格式为gif, jpg,png等
ImageIcon() ------创建未初始化的图标对象
ImageIcon(Image image)--------根据图像创建图标对象
ImageIcon (String filename) -------根据指定的图片文件创建图标对象
代码如下
public class ImageLconDemo extends JFrame {
public ImageLconDemo()
{
super("图标");
ImageIcon getlcon = new ImageIcon("");
this.setIconImage(getlcon.getImage());
this.setSize(400, 300);
this.setLocation(200, 100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void paint (Graphics g) {
ImageIcon icon = new ImageIcon("Images\\hezhao.jpg");
g.drawImage(icon.getImage(),0,20,this);
g.drawString("宽"+icon.getIconWidth()+"高"+icon.getIconHeight(),20,210);
}
public static void main(String[] args) {
new ImageLconDemo();
}
}