My program will run, and a button will appear, but the image which is in the res folder that is in a referenced library will not appear (egg.png
). There are no errors, but I'm confused as to why it won't run properly.
package gui;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
public class IconButton {
public static void main(String args[]) {
JFrame frame = new JFrame("DefaultButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon image = new ImageIcon("C:\\Users\\Jack Young\\Desktop\\Egg game Sprites");
JButton button = new JButton();
button.setIcon(image);
frame.add(button);
frame.setSize(300, 200);
frame.setResizable(false);
frame.setVisible(true);
}
}