class MyList{
private JFrame frame = new JFrame("Welcome");
private Container con = frame.getContentPane();
private JList list1 = null;
private JList list2 = null;
public MyList(){
frame.setLayout(new GridLayout(1,2));
String nation[] = {"中国","美国","日本","韩国","朝鲜","英国"};
Vector<String> v = new Vector<String>();
v.add("vn");
v.add("ez");
v.add("tm");
this.list1 = new JList(nation);
this.list2 = new JList(v);
list1.setBorder(BorderFactory.createTitledBorder("你喜欢的国家?"));
list2.setBorder(BorderFactory.createTitledBorder("你喜欢的英雄?"));
list1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
con.add(this.list1);
con.add(this.list2);
frame.setSize(300,100);
frame.setVisible(true);
this.frame.addWindowFocusListener(new WindowAdapter() {
public void windowClosing(){
System.exit(1);
}
});
}
}
public class StringBufferDemo{
public static void main(String args[]){
new MyList();
}}
第一个选择国家的列表,明明定义的时可以选择多个,但是代码运行的只能选择一个,大婶们帮我看看哪个出错了。 |