DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2006
    Posts
    3

    Exclamation PLEASE HELP!, creating an ImageIcon

    PLEASE can someone help me! Every time i try to compile my program it comes up with "cannot find symbol" for line 41, where i say try to createImageIcon. i myself cant find my problem, here is my code, could someone please find my error.

    //Keemath Heeralal
    //01-10-06
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.URL;

    public class TextFieldTry1 implements ActionListener
    {
    JFrame converterFrame;
    JPanel converterPanel;
    JTextField dateOfBirth;
    JLabel dobLabel, ageLabel, icon;
    JButton convertAge;

    public TextFieldTry1()
    {
    converterFrame = new JFrame("Keez Age Calculator");
    converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    converterFrame.setSize(new Dimension(200, 40));

    converterPanel = new JPanel(new GridLayout(2, 2));

    addContent();

    converterFrame.getRootPane().setDefaultButton(convertAge);

    converterFrame.getContentPane().add(converterPanel, BorderLayout.CENTER);

    converterFrame.pack();
    converterFrame.setVisible(true);
    }
    private void addContent()
    {
    dateOfBirth = new JTextField(2);
    dobLabel = new JLabel("Date Of Birth", SwingConstants.LEFT);
    convertAge = new JButton("<html><font color = blue>Calculate Age");
    ageLabel = new JLabel(" Years Old", SwingConstants.LEFT);
    icon = new JLabel();
    icon.setIcon(createImageIcon("images/puma.gif"));
    convertAge.addActionListener(this);

    converterPanel.add(dateOfBirth);
    converterPanel.add(dobLabel);
    converterPanel.add(convertAge);
    converterPanel.add(ageLabel);
    converterPanel.add(icon);

    dobLabel.setBorder(BorderFactory.createEmptyBorder(5,20,5,20));
    ageLabel.setBorder(BorderFactory.createEmptyBorder(5,20,5,20));
    }
    public void actionPerformed(ActionEvent e)
    {
    int dOB = Integer.parseInt(dateOfBirth.getText());
    int age = (2006 - dOB);
    ageLabel.setText("You are " + age + " years old");
    }
    public static void makeAndShowMyGui()
    {
    TextFieldTry1 myCalc = new TextFieldTry1();
    }
    public static void main(String[] args)
    {
    javax.swing.SwingUtilities.invokeLater(new Runnable()
    {
    public void run()
    {
    makeAndShowMyGui();
    }
    });
    }
    }

  2. #2
    Join Date
    Dec 2005
    Posts
    97
    why not do this:

    Code:
    icon.setIcon(new ImageIcon("images/puma.gif"));

  3. #3
    Join Date
    Oct 2006
    Posts
    3

    Unhappy still :(

    Naa i jus tried that. the only difference is that now it compiles, but stil doesnt show the picture.

    any other suggestions by any chance please???

  4. #4
    Join Date
    Sep 2006
    Posts
    68
    Check you path to image.

  5. #5
    Join Date
    Oct 2006
    Posts
    3

    Question

    Naa the paths 100% correct. the compiler says it can't find the symbol createImageIcon. thats the actual problem that honestly baffles me. . .

  6. #6
    Join Date
    Dec 2005
    Posts
    97
    it should display the image just fine...i tested it with one of my own. i did a search on createImageIcon and found that a lot of people have trouble with the compiler locating it. i myself cant even find it, so your best bet would be to use what i posted or figure out some other method.

  7. #7
    Join Date
    Sep 2006
    Posts
    68
    It works for me

    icon.setIcon(new ImageIcon(TextFieldTry1.class.getResource("images/puma.gif")));

Similar Threads

  1. JButton help
    By Dr Spud in forum Java
    Replies: 2
    Last Post: 08-17-2006, 09:34 PM
  2. Creating a session (newbie):
    By Jay in forum ASP.NET
    Replies: 2
    Last Post: 04-05-2002, 12:43 PM
  3. Defining & Creating views
    By neil in forum Database
    Replies: 2
    Last Post: 07-04-2001, 07:07 AM
  4. Creating User Defined Document in an Access Database
    By Dave Keighan in forum VB Classic
    Replies: 1
    Last Post: 02-28-2001, 12:33 PM
  5. Creating Tables with ADOX
    By Lisa in forum VB Classic
    Replies: 4
    Last Post: 10-04-2000, 07:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links