swing之checkbox


import java.awt.GridLayout;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class danfu extends JFrame{
    JPanel jp1,jp2,jp3;
    JButton jb1,jb2;
    JLabel jl1,jl2;
    JCheckBox jc1,jc2,jc3;
    JRadioButton jr1,jr2;
    ButtonGroup bg;
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        danfu df=new danfu();
    }

    
    public danfu()
       {
        jp1=new JPanel();
        jp2=new JPanel();
        jp3=new JPanel();
        
        
        jb1=new JButton("注冊");
        jb2=new JButton("取消");
        
        jl1=new JLabel("特長");
        jl2=new JLabel("性別");
        
        jc1=new JCheckBox("音樂");
        jc2=new JCheckBox("體育");
        jc3=new JCheckBox("文藝");
        
        jr1=new JRadioButton("");
        jr2=new JRadioButton("");
        
        bg=new ButtonGroup();//將單選按鈕添加到組,使其只能選擇一個
        bg.add(jr1);
        bg.add(jr2);
        
        jp1.add(jl1);
        jp1.add(jc1);
        jp1.add(jc2);
        jp1.add(jc3);
        
        jp2.add(jl2);
        jp2.add(jr1);
        jp2.add(jr2);
        
        jp3.add(jb1);
        jp3.add(jb2);
        
        
        this.setLayout(new GridLayout(3,1));
        this.add(jp1);
        this.add(jp2);
        this.add(jp3);
        
        this.setTitle("擔心");
        this.setSize(400,320);
        this.setLocation(100, 180);
        this.setResizable(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        
        
        
       }
    
    
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM