java GUI 性別單選框 日期選擇框

/***************/
		/* 性別單選框 */
		sex = new JLabel("性	    別");
		sex.setBounds(20, 105, 105, 30);
		man = new JRadioButton("男");
		man.setSelected(true);
		woman = new JRadioButton("女");
		man.setBounds(128, 105, 75, 25);
		woman.setBounds(208, 105, 75, 25);
		ButtonGroup sexgrip = new ButtonGroup();// 設置性別組,保證只能選一個
		sexgrip.add(man);
		sexgrip.add(woman);
		this.add(sex);
		this.add(man);
		this.add(woman);

 

JComboBox year1, mon1, day1,year2, mon2, day2,hour1,hour2,minute1,minute2,second1,second2;

JLabel beg_time,end_time;

/************************/
	/** 開始時間設置 **/
	beg_time = new JLabel("開始日期");
	beg_time.setBounds(20, 100, 105, 30);
	this.add(beg_time);
	/* 年下拉框 */
	Vector<String> yy = new Vector<String>();
	for (int i = 1990; i <= 2019; i++) {
		yy.add(Integer.toString(i));
	}
	year1 = new JComboBox(yy);
	year1.setBounds(120, 105, 51, 20);
	year1.setBorder(null);// 設置無邊框
	year1.setEditable(true);// 設置下拉框可編輯
	this.add(year1);
	/*******************/
	/* 月下拉框 */
	Vector<String> mm = new Vector<String>();
	for (int i = 1; i <= 12; i++) {
		String s1 = "";
		if (i < 10) {
			s1 = '0' + Integer.toString(i);
		} else {
			s1 = Integer.toString(i);
		}
		mm.add(s1);
	}
	mon1 = new JComboBox(mm);
	mon1.setBounds(171, 105, 40, 20);
	mon1.setBorder(null);// 設置無邊框
	mon1.setEditable(true);// 設置下拉框可編輯
	this.add(mon1);
	/*****************/

	/* 日下拉框 */
	Vector<String> dd = new Vector<String>();
	for (int i = 1; i <= 31; i++) {
		String s1 = "";
		if (i < 10) {
			s1 = '0' + Integer.toString(i);
		} else {
			s1 = Integer.toString(i);
		}
		dd.add(s1);
	}
	day1 = new JComboBox(dd);
	day1.setBounds(211, 105, 40, 20);
	day1.setBorder(null);// 設置無邊框
	day1.setEditable(true);// 設置下拉框可編輯
	this.add(day1);

效果顯示

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章