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

Java 如何从菜单栏打开新窗口?,java,swing,menu,jframe,joptionpane,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

这是我目前的代码:

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);
}

我正在进行一场突破赛。我想制作一个“关于”窗口,显示有关游戏的信息(例如,如何玩游戏等等)。我该怎么做呢?谢谢你的帮助!我对Java Swing非常陌生,所以是的

您可以使用消息类型
JOptionPane
执行一个简单的操作:

JOptionPane.showMessageDialog(frame, "Breakout! v1.0");
(要做到这一点,您需要将帧设置为最终帧,因为它是从匿名操作侦听器中访问的)

要获得对显示内容的更多控制,以及它是否应该是模态的,您可以查看
JDialog
。这里有一个在Swing中使用对话框的概述:。

+1另请参见