如何从菜单栏打开新窗口?

fly*_*key 4 java swing menu jframe joptionpane

到目前为止这是我的代码:

public static void main(String[] args){
    JFrame frame = new JFrame("Breakout!");
    frame.setLocation(300, 300);
    //Making the menubar
        JMenuBar mb = new JMenuBar();
        frame.setJMenuBar(mb);
        JMenu fileMenu = new JMenu("File");
        mb.add(fileMenu);
        JMenuItem newAction =   new JMenuItem("About");
        fileMenu.add(newAction);
        newAction.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                System.out.println("open new window here");
            }
        });
    BreakoutCourt c = new BreakoutCourt();
    frame.add(c);
    frame.pack();
    frame.setResizable(false);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Run Code Online (Sandbox Code Playgroud)

我正在制作突围游戏.我想创建一个关于窗口,显示有关游戏的信息(比如,如何播放等等).我该怎么做呢?感谢您的帮助!我是Java Swing的新手,所以是的.

Ash*_*Ash 5

你可以做一个简单的消息类型JOptionPane:

JOptionPane.showMessageDialog(frame, "Breakout! v1.0");
Run Code Online (Sandbox Code Playgroud)

(您需要使帧最终执行此操作,因为它是从匿名操作侦听器中访问的).

为了更好地控制显示的内容,以及它是否应该是模态的,你可以看一下JDialog.这里有一个关于在Swing中使用对话框的概述:http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html.