-
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();
}
});
}
}
-
why not do this:
Code:
icon.setIcon(new ImageIcon("images/puma.gif"));
-
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???
-
-
Naa the paths 100% correct. the compiler says it can't find the symbol createImageIcon. thats the actual problem that honestly baffles me. . .
-
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.
-
It works for me
icon.setIcon(new ImageIcon(TextFieldTry1.class.getResource("images/puma.gif")));
Similar Threads
-
Replies: 2
Last Post: 08-17-2006, 09:34 PM
-
Replies: 2
Last Post: 04-05-2002, 12:43 PM
-
By neil in forum Database
Replies: 2
Last Post: 07-04-2001, 07:07 AM
-
By Dave Keighan in forum VB Classic
Replies: 1
Last Post: 02-28-2001, 12:33 PM
-
By Lisa in forum VB Classic
Replies: 4
Last Post: 10-04-2000, 07:00 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks