try { BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated; //UIManager.put("RootPane.setupButtonVisible", false); org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF(); } catch(Exception e) { //TODO exception } // 创建窗体对象 JFrame jFrame =new JFrame(); // 设置窗体大小 jFrame.setSize(800, 500); // 设置窗体全屏展示 //jFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); // 设置窗体显示位置 //jFrame.setLocation(100,200); // 设置窗体显示正中间 jFrame.setLocationRelativeTo(null); // 设置窗体标题 jFrame.setTitle("窗体标题"); // 设置窗体不可全屏显示 //jFrame.setResizable(false); // 设置窗体关闭后退出程序 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置此窗口是否应该始终位于其他窗口上方 jFrame.setAlwaysOnTop(true); // 设置窗体图标 jFrame.setIconImage(new ImageIcon(HelloWorld.class.getResource("/images/book.png")).getImage()); // 创建容器 JPanel jPanel =new JPanel(new FlowLayout()); JRadioButton nan =new JRadioButton("男",false); JRadioButton nv =new JRadioButton("女",true); // ButtonGroup实现互斥 ButtonGroup group =new ButtonGroup(); group.add(nv); group.add(nan); JButton btn =new JButton("提交"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(nan.isSelected()) { System.out.println(nan.getText()); } if(nv.isSelected()) { System.out.println(nv.getText()); } } }); jPanel.add(btn); jPanel.add(nan); jPanel.add(nv); jFrame.setContentPane(jPanel); // 设置窗体可见 jFrame.setVisible(true);
标签:jFrame,JRadioButton,add,窗体,设置,new,JavaSwing From: https://www.cnblogs.com/liangqingyun/p/18591408