I did this but the .gif does not show up. The load.gif is in the same package (chapter 10) as the project.
If I take these files to a default package it will work. So I know there must be a way to call the gif (ie make a dir to find the image)
Can someone help please
[size=2]Here is my code[/size]
[size=2][/size]
Expand|Select|Wrap|Line Numbers
- package chapter10;
- import java.awt.BorderLayout;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JToolBar;
- public class FeedBar2 extends JFrame {
- public FeedBar2() {
- super("FeedBar 2");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- // create icons
- ImageIcon loadIcon = new ImageIcon("load.gif");
- // create buttons
- JButton load = new JButton("Load", loadIcon);
- // add buttons to toolbar
- JToolBar bar = new JToolBar();
- bar.add(load);
- // prepare user interface
- JTextArea edit = new JTextArea(8, 40);
- JScrollPane scroll = new JScrollPane(edit);
- BorderLayout bord = new BorderLayout();
- setLayout(bord);
- add("North", bar);
- add("Center", scroll);
- pack();
- setVisible(true);
- }
- public static void main(String[] arguments) {
- FeedBar2 frame = new FeedBar2();
- }
Expand|Select|Wrap|Line Numbers
- }
[/size]nomad