当我运行此代码时,不会出现menuItems。我在我的主类中调用了这个Menu方法。 JFrame确实显示白色菜单栏,但没有menuItems,也没有下拉列表。关于如何解决这个问题的任何建议。
public void createScreen() {
this.setVisible(true);
this.setBackground(Color.white);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setTitle("SpreadSheets");
this.setSize(w, h);
}
public void resizerValue() {
w = this.getWidth();
h = this.getHeight();
}
public void Menu() {
JMenuBar menuBar = new JMenuBar();
// creates bar
JMenu menu = new JMenu("File");
// makes the menu
JMenuItem mnuNew = new JMenuItem(ACTION_NEW);
JMenuItem mnuLoad = new JMenuItem(ACTION_LOAD);
JMenuItem mnuSave = new JMenuItem(ACTION_SAVE);
// creates the menuItems
mnuNew.setActionCommand(ACTION_NEW);
mnuLoad.setActionCommand(ACTION_LOAD);
mnuSave.setActionCommand(ACTION_SAVE);
// sets the items commands in the ActionCommand
mnuNew.addActionListener(this);
mnuLoad.addActionListener(this);
mnuSave.addActionListener(this);
// adds the functions to the action Listener
menu.add(mnuNew);
menu.add(mnuSave);
menu.add(mnuLoad);
menuBar.add(menu);
// adds them to menu
this.setJMenuBar(menuBar);
// adds this menu to the bar
}
@Override
public void actionPerformed(ActionEvent e) {
}
}