I have created a Registration form using java swing package, For the purpose of adding Date of Birth in the form I have used the following code particularly to add a JFrame via Swing Package. Is there any alternative way to simplify the code.
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);
Here’s the source code for a calendar picker I wrote several years ago. I’m not including all the dependencies like graphic files etc, but I’m pretty sure you can figure out what’s missing and reproduce it. I wrote it for a department in a company that closed down that department, so I doubt anybody is going to be claiming copyright on it.
http://dl.dropbox.com/u/15266/SmallCalendar.java
http://dl.dropbox.com/u/15266/DateFormatInfo.java
Note that SmallCalendar includes a main so you can test it and see how it’s meant to be called. It’s pretty good about Locales.