With the following code the icons will not appear unless I specify the entire path to where they are located, I cant work out why it wont work, what am I missing?
Thanks for any help
Expand|Select|Wrap|Line Numbers
- public class IconFrame extends JFrame {
- JButton load, save, subscribe, unsubscribe;
- public IconFrame() {
- super("Icon Frame");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- // create icons
- ImageIcon loadIcon = new ImageIcon("load.gif");
- ImageIcon saveIcon = new ImageIcon("save.gif");
- ImageIcon subscribeIcon = new ImageIcon("subscribe.gif");
- ImageIcon unsubscribeIcon = new ImageIcon("unsubscribe.gif");
- // create buttons
- load = new JButton("Load", loadIcon);
- save = new JButton("Save", saveIcon);
- subscribe = new JButton("Subscribe", subscribeIcon);
- unsubscribe = new JButton("Unsubscribe", unsubscribeIcon);
- // add buttons to panel
- panel.add(load);
- panel.add(save);
- panel.add(subscribe);
- panel.add(unsubscribe);
- // add the panel to a frame
- add(panel);
- pack();
- setVisible(true);
- }
- public static void main(String[] arguments) {
- IconFrame ike = new IconFrame();
- }
- }