Java Help

Stokes

Senior member
Apr 20, 2005
510
0
0
Im having trouble just getting started and can't figure out why my image isnt showing up. or the background change isnt working. I'm recieving this error:

guiinventory.java:31: cannot find symbol
symbol : method add(javax.swing.ImageIcon)
location: class javax.swing.JPanel
buttonpanel.add(mother);
^




import javax.swing.*; //for all the GUI components
import java.awt.event.*; //For ActionLisenter Interface
import java.awt.*;


public class guiinventory
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
final int FRAME_WIDTH = 500; //setting my window dimensions
final int FRAME_HEIGHT = 500;
frame.setBackground(Color.white);

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Martin's General Store");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


Inventory cpu = new Inventory(25, 199.99);
Inventory motherboard = new Inventory(38,120);
Inventory graphics = new Inventory(20, 250);

JPanel buttonpanel = new JPanel();

ImageIcon mother = new ImageIcon("img/mother.gif");
final JButton motherbutton = new JButton("mother");



buttonpanel.add(mother);

frame.add(buttonpanel);
frame.setVisible(true);
}

}
 

elmro

Senior member
Dec 4, 2005
459
0
0
1) wrong forum
2) you can't add an ImageIcon using add(), it only takes Component classes (atleast in 1.4)