Java - createImageIcon() not recognized in code?

imageicon, java, swing

Solution

Should it actually be:

ImageIcon icon = new ImageIcon("images/middle.gif","this is a caption");

so that you're calling the constructor for a new ImageIcon object?

Problem

I keep getting an error that createImageIcon() is not recognized as an available function. Not sure why this is occuring, as I feel like I have loaded the libraries that I need for it. ``` ImageIcon icon = createImageIcon("images/middle.gif","this is a caption"); ``` I've tried using different arguments, etc., but can't seem to figure it out. ``` import javax.swing.*; import javax.swing.ImageIcon; import java.awt.*; import java.awt.image.BufferStrategy; public class main extends JFrame { public main() { } public static void main(String[] args) { JMenuBar menuBar = new JMenuBar(); JMenu Menu_File = new JMenu("TEST MENU"); JMenu Menu_File_New = new JMenu("New"); ImageIcon icon = createImageIcon("images/middle.gif","this is a caption"); Menu_File.add(Menu_File_New); JMenuItem Menu_File_New_Project = new JMenuItem("Project..."); JMenuItem Menu_File_New_Burrito = new JMenuItem("Burrito..."); JMenuItem Menu_File_New_Cookie = new JMenuItem("Cookie..."); JMenuItem Menu_File_New_Other = new JMenuItem("Other..."); Menu_File_New.add(Menu_File_New_Project); Menu_File_New.add(Menu_File_New_Burrito); Menu_File_New.add(Menu_File_New_Cookie); Menu_File_New.add(Menu_File_New_Other); JMenuItem Menu_File_Open = new JMenuItem("Open..."); JMenuItem Menu_File_Save = new JMenuItem("Save"); JMenuItem Menu_File_SaveAs = new JMenuItem("Save As..."); JMenuItem Menu_File_Reload= new JMenuItem("Reload"); Menu_File.add(Menu_File_Open); Menu_File.add(Menu_File_Save); Menu_File.add(Menu_File_SaveAs); Menu_File.add(Menu_File_Reload); Menu_File.addSeparator(); JMenuItem Menu_File_Screenshot = new JMenuItem("Take Screenshot"); Menu_File.add(Menu_File_Screenshot); Menu_File.addSeparator(); JMenuItem Menu_File_Exit = new JMenuItem("Exit"); Menu_File.add(Menu_File_Exit); menuBar.add(Menu_File); JMenu Menu_Edit = new JMenu("Edit"); JMenu Menu_Windows = new JMenu("Windows"); JMenu Menu_Mode = new JMenu("Mode"); JMenu Menu_Help = new JMenu("Help"); menuBar.add(Menu_Edit); menuBar.add(Menu_Windows); menuBar.add(Menu_Mode); menuBar.add(Menu_Help); main frame = new main(); frame.setJMenuBar(menuBar); // Create menu and associate with frame frame.setTitle("3DAirspace"); frame.setUndecorated(true); //frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } } ```

Original source