检查是否按下了菜单项

时间:2019-05-06 08:57:23

标签: java eclipse swing jframe windowbuilder

我想让GUI做一些与菜单项交互的操作,但是我无法使其正常工作...我已经尝试了actionlisteners n东西,但是什么也没有... 在Eclipse IDE中使用WindowBuilder

public menu() 
{
    setTitle("Alkku's AIO");
    setResizable(false);
    getContentPane().setLayout(null);

    JButton startButton = new JButton("Start");
    startButton.setBounds(10, 216, 424, 23);
    getContentPane().add(startButton);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnNewMenu = new JMenu("Scripts");
    menuBar.add(mnNewMenu);

    JRadioButton rdbtnNewRadioButton = new JRadioButton("option1");
    rdbtnNewRadioButton.addActionListener(new ActionListener() 
    {
        public void actionPerformed(ActionEvent arg0)
        {
            startButton.setVisible(false); //this is just an example since i wanted to test if it this works...
        }
    });
    buttonGroup.add(rdbtnNewRadioButton);
    mnNewMenu.add(rdbtnNewRadioButton);

    JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("option2");
    buttonGroup.add(rdbtnNewRadioButton_1);
    mnNewMenu.add(rdbtnNewRadioButton_1);
}

0 个答案:

没有答案