/Users/16484/Downloads/IA Prototype - Shubha N 4/src/ia/prototype/shubha/n/DateLabelFormatter.java |
1 package ia.prototype.shubha.n;
2
3
4
5
6
7
8 import java.text.ParseException;
9 import java.text.SimpleDateFormat;
10 import java.util.*;
11 import javax.swing.JFormattedTextField.AbstractFormatter;
12
13
14 @author
15
16
17 public class DateLabelFormatter extends AbstractFormatter {
18
19 DateLabelFormatter(){
20 Calendar cal = Calendar.getInstance();
21 }
22 private String datePattern = "dd-MM-yyyy";
23 private SimpleDateFormat dateFormatter = new SimpleDateFormat(datePattern);
24
25 @Override
26 public Object stringToValue(String text) throws ParseException {
27 return dateFormatter.parseObject(text);
28 }
29
30 @Override
31 public String valueToString(Object value) throws ParseException {
32 if (value != null) {
33 Calendar cal = (Calendar) value;
34 return dateFormatter.format(cal.getTime());
35 }
36
37 return "";
38 }
39
40 }