我使用java swing包创建了一个Registration表单,为了在表单中添加出生日期,我使用了以下代码,特别是通过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);
最佳答案
这是几年前我写的日历选择器的源代码。我没有包括图形文件等所有依赖项,但我很确定您可以找出缺失的内容并重现它。我是为关闭该部门的公司的一个部门编写的,所以我怀疑有人会要求版权。
http://dl.dropbox.com/u/15266/SmallCalendar.java
http://dl.dropbox.com/u/15266/DateFormatInfo.java
请注意,SmallCalendar包含一个main,因此您可以对其进行测试并查看其调用方式。关于Locales很好。
关于java - 使用swing包的简单Java表单在Calendar中需要向导吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12843459/