0

我使用 java swing 包创建了一个注册表单,为了在表单中添加出生日期,我使用了以下代码,特别是通过 Swing 包添加了一个 JFrame。有没有其他方法可以简化代码。

JLabel l2 = new JLabel("Date of Birth");

l2.setBounds(200,160,100,20);
String day[] ={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30"};
String month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
String year[] = {"2012","2011","2010","2009","2008","2007","2006","2005","2004","2003","2002","2001","2000","1999","1998","1997","1996","1995","1994","1993","1992","1991","1990","1989","1988","1987","1986","1985","1984","1983","1982","1981","1980","1979","1976","1975"};
JComboBox cb1 = new JComboBox(day);
cb1.setBounds(450,160,50,20);
JComboBox cb2 = new JComboBox(month);
cb2.setBounds(500,160,50,20);
JComboBox cb3 = new JComboBox(year);
cb3.setBounds(550,160,60,20);
4

1 回答 1

2

这是我几年前编写的日历选择器的源代码。我没有包括图形文件等所有依赖项,但我很确定您可以找出丢失的内容并重现它。我是为关闭该部门的公司的一个部门写的,所以我怀疑有人会声称它的版权。

http://dl.dropbox.com/u/15266/SmallCalendar.java

http://dl.dropbox.com/u/15266/DateFormatInfo.java

请注意,SmallCalendar 包含一个 main,因此您可以对其进行测试并查看它是如何被调用的。Locales 挺好的。

于 2012-10-11T17:00:39.357 回答