我有一個圖形用戶界面我想添加一個菜單欄,但每次我嘗試添加JmenuBar時都會說它期望java.awt.menubar,並且找到了一個java.swing.Jmenubar,它就是它應該檢測。這是我的代碼。不能設置JMenuBar
class CipherGUIFrame extends JFrame{
public CipherGUIFrame(){
super("Caesar Cipher GUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 600);
Container content = getContentPane();
content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("File");
open = new JMenuItem("Open");
save = new JMenuItem("Close");
menu.add(open);
menu.add(save);
menuBar.add(menu);
setMenuBar(menuBar); // this line here is what gives me the error
}
}
的方法是set'J'MenuBar。 – camickr
嘗試setJMenuBar,並記住使用API,因爲它會告訴你所有這些,並且比我們更快。 –
我很遲鈍謝謝。 – user541597