下拉框

一、代码如下

package www.tainiu.gui;

import java.awt.GridLayout;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class ac__XiaLaKuang__V1 extends JFrame {
	JPanel jp1,jp2;
	JLabel jl1,jl2;
	JComboBox jcb;
	JList jl;
	JScrollPane jsp;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ac__XiaLaKuang__V1 xv= new ac__XiaLaKuang__V1();
	}
	
	public ac__XiaLaKuang__V1() {
		// TODO Auto-generated constructor stub
		//定义组件
		this.jp1= new JPanel();
		this.jp2= new JPanel();
		this.jl1= new JLabel("您的籍贯是");
		this.jl2= new JLabel("您喜欢旅游的地方是");
		
		String[] jg= {"四川", "北京", "上海", "重庆", "云南"};
		this.jcb= new JComboBox(jg);
		
		String[] lvjd={"乐山", "眉山", "卧龙", "恐龙博物馆", "故宫", "长城", "颐和园"};
		this.jl= new JList(lvjd);
		this.jl.setVisibleRowCount(2);
		jsp= new JScrollPane(this.jl);
		
		
		//布局格式
		this.setLayout(new GridLayout(3, 1));
		//添加组件
		this.jp1.add(this.jl1);
		this.jp1.add(this.jcb);
		this.jp2.add(this.jl2);
		//this.jp2.add(this.jl);
		this.jp2.add(jsp);
		
		this.add(this.jp1);
		this.add(this.jp2);
		
		//容器属性设置
		this.setSize(400, 150);
		this.setLocation(200, 200);
		//this.setResizable(false);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}

	
}

 

posted @ 2017-09-19 19:45  18513757531  阅读(245)  评论(0编辑  收藏  举报