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 import java.util.Vector;
 8 
 9 import javax.swing.BorderFactory;
10 import javax.swing.JCheckBox;
11 import javax.swing.JComboBox;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.JRadioButton;
16 
17 class MyRadio{
18     private JFrame f=new JFrame("welcome to use!");
19     private Container cont=f.getContentPane();
20     private JComboBox jcb1=null;
21     private JComboBox jcb2=null;
22     public MyRadio(){
23         this.f.setLayout(new GridLayout(2,2));
24         String nations[]={"China","Brazil","America","Korean","Italy","France"
25     };
26         Vector<String> v=new Vector<String>();
27         v.add("hjw");
28         v.add("LJD");
29         v.add("zk");
30         this.jcb1=new JComboBox(nations);
31         this.jcb2=new JComboBox(v);
32         jcb1.setBorder(BorderFactory.createTitledBorder("Which country do you want to travel?"));
33         jcb2.setBorder(BorderFactory.createTitledBorder("Who do you like best?"));
34         jcb1.setMaximumRowCount(3);
35         jcb2.setMaximumRowCount(3);
36         cont.add(this.jcb1);
37         cont.add(this.jcb2);
38         cont.add(new JLabel("下拉框"));
39         this.f.setSize(300,150);
40         this.f.setVisible(true);
41         this.f.addWindowListener(new WindowAdapter(){
42             public void windowClosing(WindowEvent arg0){
43                 System.exit(1);
44             }
45         });
46     }
47 }
48 public class test {
49     public static void main(String[] args) {
50         new MyRadio();
51         
52     }
53 
54 
55 }

 

你可能感兴趣的:(java 下拉列表框)