简体   繁体   English

JMenu-JMenuItem没有出现

[英]JMenu-JMenuItem doesn't appear

My problem with this code is that when I run it the JMenuItem doesn't appear. 我对这段代码的问题是,当我运行它时, JMenuItem不会出现。 I'm so confused! 我很混乱! Anyone can help? 有人可以帮忙吗?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NewClass extends JFrame implements ActionListener{
JFrame window = new JFrame("Ηλεκτρονικό Έντυπο Υπερωριών");
JMenu menu = new JMenu("Example");
JMenuItem menuItem = new JMenuItem("hi");
public NewClass(){
    window.setSize(200,200);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    menu.add(menuItem);
    menuItem.addActionListener(this);

    window.add(menu);
    window.pack();
    window.setVisible(true);
        }
public static void main(String []args){
    NewClass example = new NewClass();
}

@Override
public void actionPerformed(ActionEvent ae) {
    throw new UnsupportedOperationException("Not supported yet.");
    }
}

You need to add a menubar to the window. 您需要在窗口中添加菜单栏。 To this menubar you add your menu(s). 在这个菜单栏中添加菜单。 Take a look at oracle's tutorial on How to Use Menus . 看一下oracle关于如何使用菜单的教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM