• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Help

Stokes

Senior member
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);
}

}
 
1) wrong forum
2) you can't add an ImageIcon using add(), it only takes Component classes (atleast in 1.4)
 
Back
Top