Import Java.io.File;
Import java.io.IOException;
Import Java.awt.BorderLayout;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Javax.swing.Icon;
Import Javax.swing.ImageIcon;
Import Javax.swing.JButton;
Import Javax.swing.JFrame;
Import Javax.swing.JPanel;
Import Javax.swing.JTextField;
Import Javax.swing.JLabel;
Import Javax.swing.BoxLayout;
Import Javax.swing.filechooser.FileSystemView;
Import Sun.awt.shell.ShellFolder;
public class Fileiconextractor extends JFrame implements actionlistener{
Private JButton geticonbtn = new JButton ("Get Icon");
Private JPanel Iconpanel = new JPanel ();
Private JTextField Extfield = new JTextField ();
Private JLabel Smalliconlabel = new JLabel ("small Icon here");
Private JLabel Bigiconlabel = new JLabel ("Big Icon here");
Public Fileiconextractor () {
This.setsize (200, 150);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.setlayout (New BorderLayout ());
Geticonbtn.setactioncommand ("GetIcon");
Geticonbtn.addactionlistener (this);
Iconpanel.setlayout (New BoxLayout (Iconpanel, Boxlayout.y_axis));
Iconpanel.add (Smalliconlabel);
Iconpanel.add (Bigiconlabel);
This.add (Extfield, Borderlayout.north);
This.add (Iconpanel, Borderlayout.center);
This.add (GETICONBTN, Borderlayout.south);
This.setvisible (TRUE);
}
public void actionperformed (ActionEvent e) {
if (E.getactioncommand (). Equals ("GetIcon")) {
String ext = Extfield.gettext ();
File file;
Try
{
File = File.createtempfile ("icon", "." + ext);
FileSystemView view = Filesystemview.getfilesystemview ();
Icon SmallIcon = view.getsystemicon (file);
ShellFolder ShellFolder = shellfolder.getshellfolder (file);
Icon Bigicon = new ImageIcon (Shellfolder.geticon (true));
Seticonlabel (SmallIcon, Bigicon);
File.delete ();
}
catch (IOException IoE)
{
Ioe.printstacktrace ();
}
}
}
private void Seticonlabel (icon smallicon, icon Bigicon) {
Smalliconlabel.seticon (SmallIcon);
Bigiconlabel.seticon (Bigicon);
}
public static void Main (string[] args) {
Fileiconextractor fie = new Fileiconextractor ();
}
}