posted 12 years ago
I would probably have gone for JLabel instead of JTextField, but there's little difference.
You do have an issue with your text, a mistake many users make when working with Calendar: the month returned by get(Calendar.MONTH) starts at 0, so for today "mo" would be 3, not 4. I suggest using a DateFormat instead:
Added advantages:
1) you don't have to worry about adding extra zeros; your code could have shown a time of "4:5:3", my code will turn that into "4:05:03" because of the "mm" and "ss". You can do the same for the month and year (yyyy is quite common).
2) you don't need to create a Calendar instance; the commented out line of code would be enough. Well, unless you need timezone specifics, but usually you don't need to worry about this.
Note that the DateFormat is accessed only in the EDT and is therefore thread-safe.