0

谁能帮助解释为什么这不起作用?

        menuItem = new JMenuItem("Document");
                menuItem.addActionListener(new ActionListener()
                        {
                            public void actionPerformed(ActionEvent e)
                            {
                                System.out.println("button clicked!");
                            }
                        });
        submenu.add(menuItem);

谢谢!

4

1 回答 1

2
menuItem = new JMenuItem("Document");
    menuItem.addActionListener(new ActionListener()
            menuItem.addActionListener(new ActionListener()   //You don't need it again.
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            System.out.println("button clicked!");
                        }
                    });
    submenu.add(menuItem);

试试这个:

menuItem = new JMenuItem("Document");
    menuItem.addActionListener(new ActionListener()
                    {
                        public void actionPerformed(ActionEvent e)
                        {
                            System.out.println("button clicked!");
                        }
                    });
    submenu.add(menuItem);
于 2013-02-21T09:25:23.730 回答