I'm having trouble creating a button with an icon in java, I've looked at several tutorials, but I can not get it to work.
Note: I am using eclipse, Windows 10. The folder that is in the image is src where the Main class file is.
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame();
Icon imageIcon = new ImageIcon("flag.png");
frame.add(new JButton("Flag",imageIcon));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,400);
frame.setVisible(true);
}
}