我不斷收到一個錯誤,createImageIcon()不被識別爲可用函數。不知道爲什麼會出現這種情況,因爲我覺得我已經加載了我需要的庫。Java - createImageIcon()在代碼中無法識別?
ImageIcon icon = createImageIcon("images/middle.gif","this is a caption");
我試過使用不同的參數等,但似乎無法弄清楚。
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);
}
}
這工作,謝謝! :) – IDontWorkAtNASA 2013-04-05 18:41:10