0
我的JMenuBar沒有顯示AT ALL。這只是一個準系統GUI。我在這裏坐了好一會兒,我看不出問題,呃,正如他們所說,四隻眼睛比兩隻眼睛好。Java Swing JMenuBar
謝謝。
import javax.swing.*;
import java.awt.*;
public class MainGui{
private DrawPanel drawPanel;
private JFrame mainFrame;
private JPanel drawPanel;
private JMenuBar menuBar;
private JMenu fileMenu, imgMenu, helpMenu;
private JMenuItem fileNew, fileOpen, fileSave, fileExit;
private JMenuItem imgBtn1;
private JMenuItem hlpAbout;
public MainGui(DrawPanel drawPanel){
mainFrame = new JFrame("JDraw v1");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setLayout(new BorderLayout());
this.drawPanel = drawPanel;
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
imgMenu = new JMenu("Image");
helpMenu = new JMenu("Help");
fileNew = new JMenuItem("New File");
fileOpen = new JMenuItem("Open File");
fileSave = new JMenuItem("Save File");
fileExit = new JMenuItem("Exit");
imgBtn1 = new JMenuItem("Useless Button");
hlpAbout = new JMenuItem("About this program");
mainFrame.add(menuBar, BorderLayout.PAGE_START);
menuBar.add(fileMenu);
menuBar.add(imgMenu);
menuBar.add(hlpMenu);
fileMenu.add(fileNew);
fileMenu.add(fileOpen);
fileMenu.add(fileSave);
fileMenu.add(fileExit);
imgMenu.add(imgBtn1);
helpMenu.add(hlpAbout);
mainFrame.add(drawPanel, BorderLayout.CENTER);
mainFrame.pack();
mainFrame.setSize(640,480);
mainFrame.setResizable(false);
mainFrame.setVisible(true);
}
}
正常工作對我來說,一旦我修復編譯錯誤當然。 –
編譯錯誤;奇怪,我從來沒有得到任何。當然,我認爲你刪除了對drawPanel的引用? –
聲明爲'helpMenu'的變量,引用爲'hlpMenu'。 –