设置勾选,以及注释,监听

frame.setJMenuBar(ba);//页面的头部,菜单。
JCheckBox married = new JCheckBox(“是否已婚”,false);//名字,后面是否为√,勾选框
JRadioButton male = new JRadioButton(“男”, true); //圆点选择框
JRadioButton female = new JRadioButton(“女”, false);

当鼠标在目录JMenuItem中时,会有提示
newItem.setToolTipText(“新建一个呀!”);

设置快捷键,并设置监听
newItem.setAccelerator(KeyStroke.getKeyStroke(‘N’,InputEvent.CTRL_MASK));
newItem.addActionListener(e->ta.append(“用户单击新建菜单\n”));

另一种事件监听
ActionListener newActions = e->{
ta.append(“用户要复制咯!”);
};
copyItem.addActionListener(newActions);

猜你喜欢

转载自blog.csdn.net/so_band/article/details/80986840