java 显示单选按钮

 1 package test;
 2 
 3 import java.awt.Container;
 4 import java.awt.GridLayout;
 5 import java.awt.event.WindowAdapter;
 6 import java.awt.event.WindowEvent;
 7 
 8 import javax.swing.BorderFactory;
 9 import javax.swing.JFrame;
10 import javax.swing.JPanel;
11 import javax.swing.JRadioButton;
12 
13 class MyRadio{
14     private JFrame f=new JFrame("welcome to use!");
15     private Container cont=f.getContentPane();
16     private JRadioButton jb1=new JRadioButton("HJW");
17     private JRadioButton jb2=new JRadioButton("ZK");
18     private JRadioButton jb3=new JRadioButton("LJD");
19     private JPanel pan=new JPanel();
20     public MyRadio(){
21         pan.setBorder(BorderFactory.createTitledBorder("Choose one Of belows:"));
22         pan.setLayout(new GridLayout(1, 3));
23         pan.add(this.jb1);
24         pan.add(this.jb2);
25         pan.add(this.jb3);
26         cont.add(pan);
27         this.f.setSize(330, 80);
28         this.f.setVisible(true);
29         this.f.addWindowListener(new WindowAdapter(){
30             public void windowClosing(WindowEvent arg0){
31                 System.exit(1);
32             }
33         });
34     }
35 }
36 public class test {
37     public static void main(String[] args) {
38         new MyRadio();
39         
40     }
41 
42 }

 

你可能感兴趣的:(java 显示单选按钮)