我在网上找了个日期控件..为什么这个控件不能选择日期啊.
  我希望我选项择某一天的时候能返回当天的日期字符串.哪位朋友能给我改一下.让我选择某一天的时候返回当天的日期字符串package com.ui;import java.awt.*; 
import java.awt.event.*; 
import java.util.*; 
import javax.swing.*; 
import javax.swing.event.*; 
import javax.swing.table.*;
 
public class MyCalendar extends JApplet {
 
    public static final String WEEK_SUN = "日"; 
    public static final String WEEK_MON = "一"; 
    public static final String WEEK_TUE = "二"; 
    public static final String WEEK_WED = "三"; 
    public static final String WEEK_THU = "四"; 
    public static final String WEEK_FRI = "五"; 
    public static final String WEEK_SAT = "六";
 
    public static final Color background = Color.white; 
    public static final Color foreground = Color.black; 
    public static final Color headerBackground = Color.blue; 
    public static final Color headerForeground = Color.white; 
    public static final Color selectedBackground = Color.blue; 
    public static final Color selectedForeground = Color.white;
 
    private JPanel cPane; 
    private JLabel yearsLabel; 
    private JSpinner yearsSpinner; 
    private JLabel monthsLabel; 
    private JComboBox monthsComboBox; 
    private JTable daysTable; 
    private AbstractTableModel daysModel; 
    private Calendar calendar; 
    
    public MyCalendar() { 
        cPane = (JPanel) getContentPane(); 
    }
 
    public void init() { 
        cPane.setLayout(new BorderLayout());
 
        calendar = Calendar.getInstance(); 
        calendar = Calendar.getInstance();
        yearsLabel = new JLabel("年: "); 
        yearsSpinner = new JSpinner(); 
        yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));
        yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR))); 
        yearsSpinner.addChangeListener(new ChangeListener() { 
                public void stateChanged(ChangeEvent changeEvent) { 
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue()).intValue());
                    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                    updateView(); 
                } 
            });
 
        JPanel yearMonthPanel = new JPanel(); 
        cPane.add(yearMonthPanel, BorderLayout.NORTH); 
        yearMonthPanel.setLayout(new BorderLayout()); 
        yearMonthPanel.add(new JPanel(), BorderLayout.CENTER); 
        JPanel yearPanel = new JPanel(); 
        yearMonthPanel.add(yearPanel, BorderLayout.WEST); 
        yearPanel.setLayout(new BorderLayout()); 
        yearPanel.add(yearsLabel, BorderLayout.WEST); 
        yearPanel.add(yearsSpinner, BorderLayout.CENTER);
 
        monthsLabel = new JLabel("月: "); 
        monthsComboBox = new JComboBox(); 
        for (int i = 1; i <= 12; i++) { 
            monthsComboBox.addItem(new Integer(i)); 
        } 
        monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH)); 
        monthsComboBox.addActionListener(new ActionListener() { 
                public void actionPerformed(ActionEvent actionEvent) {
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex());
                    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
                    updateView(); 
                } 
            }); 
        JPanel monthPanel = new JPanel(); 
        yearMonthPanel.add(monthPanel, BorderLayout.EAST); 
        monthPanel.setLayout(new BorderLayout()); 
        monthPanel.add(monthsLabel, BorderLayout.WEST); 
        monthPanel.add(monthsComboBox, BorderLayout.CENTER);
 
        daysModel = new AbstractTableModel() { 
                public int getRowCount() { 
                    return 7; 
                }
 
                public int getColumnCount() { 
                    return 7; 
                }
 
                public Object getValueAt(int row, int column) { 
                    if (row == 0) { 
                        return getHeader(column); 
                    } 
                    row--; 
                    Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();
                    calendar.set(Calendar.DAY_OF_MONTH, 1);
                    int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
                    int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1; 
                    int index = row * 7 + column; 
                    int dayIndex = index - moreDayCount + 1;
                    if (index < moreDayCount || dayIndex > dayCount) { 
                        return null; 
                    } else { 
                        return new Integer(dayIndex); 
                    } 
                } 
            };
 
        daysTable = new CalendarTable(daysModel, calendar); 
        daysTable.setCellSelectionEnabled(true);
        daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
 
        daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() { 
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 
                                                               boolean hasFocus, int row, int column) { 
                    String text = (value == null) ? "" : value.toString(); 
                    JLabel cell = new JLabel(text); 
                    cell.setOpaque(true); 
                    if (row == 0) { 
                        cell.setForeground(headerForeground); 
                        cell.setBackground(headerBackground); 
                    } else { 
                        if (isSelected) { 
                            cell.setForeground(selectedForeground); 
                            cell.setBackground(selectedBackground); 
                        } else { 
                            cell.setForeground(foreground); 
                            cell.setBackground(background); 
                        } 
                    }
 
                    return cell; 
                } 
            });
        updateView();
 
        cPane.add(daysTable, BorderLayout.CENTER); 
    }
 
    public static String getHeader(int index) { 
        switch (index) { 
        case 0: 
            return WEEK_SUN; 
        case 1: 
            return WEEK_MON; 
        case 2: 
            return WEEK_TUE; 
        case 3: 
            return WEEK_WED; 
        case 4: 
            return WEEK_THU; 
        case 5: 
            return WEEK_FRI; 
        case 6: 
            return WEEK_SAT; 
        default: 
            return null; 
        } 
    }
 
    public void updateView() { 
        daysModel.fireTableDataChanged();
        daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),
                                          calendar.get(Calendar.WEEK_OF_MONTH));
        daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1,
                                             calendar.get(Calendar.DAY_OF_WEEK) - 1);
    }
    public static class CalendarTable extends JTable {
        private Calendar calendar;
        public CalendarTable(TableModel model, Calendar calendar) {
            super(model);
            this.calendar = calendar;
        }
        public void changeSelection(int row, int column, boolean toggle, boolean extend) {
            super.changeSelection(row, column, toggle, extend);
            if (row == 0) {
                return;
            }
            Object obj = getValueAt(row, column);
            if (obj != null) {
                calendar.set(Calendar.DAY_OF_MONTH, ((Integer)obj).intValue());
            }
        }
    }
 
    public static void main(String[] args) { 
        JFrame frame = new JFrame("Calendar Application"); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        MyCalendar myCalendar = new MyCalendar(); 
        myCalendar.init(); 
        frame.getContentPane().add(myCalendar); 
        frame.setSize(240, 172); 
        frame.show(); 
    }
 
}

解决方案 »

  1.   

    不会swing,加了个双击table取值的,其他不会了。
    package test;import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.table.*;public class MyCalendar extends JApplet { public static final String WEEK_SUN = "日"; public static final String WEEK_MON = "一"; public static final String WEEK_TUE = "二"; public static final String WEEK_WED = "三"; public static final String WEEK_THU = "四"; public static final String WEEK_FRI = "五"; public static final String WEEK_SAT = "六"; public static final Color background = Color.white; public static final Color foreground = Color.black; public static final Color headerBackground = Color.blue; public static final Color headerForeground = Color.white; public static final Color selectedBackground = Color.blue; public static final Color selectedForeground = Color.white; private JPanel cPane; private JLabel yearsLabel; private JSpinner yearsSpinner; private JLabel monthsLabel; private JComboBox monthsComboBox; private JTable daysTable; private AbstractTableModel daysModel; private Calendar calendar; private String value; public String getValue() {
    return this.value;
    } public MyCalendar() {
    cPane = (JPanel) getContentPane();
    } public void init() {
    cPane.setLayout(new BorderLayout()); calendar = Calendar.getInstance();
    calendar = Calendar.getInstance();
    yearsLabel = new JLabel("年: ");
    yearsSpinner = new JSpinner();
    yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000"));
    yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR)));
    yearsSpinner.addChangeListener(new ChangeListener() {
    public void stateChanged(ChangeEvent changeEvent) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue())
    .intValue());
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar
    .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
    updateView();
    }
    }); JPanel yearMonthPanel = new JPanel();
    cPane.add(yearMonthPanel, BorderLayout.NORTH);
    yearMonthPanel.setLayout(new BorderLayout());
    yearMonthPanel.add(new JPanel(), BorderLayout.CENTER);
    JPanel yearPanel = new JPanel();
    yearMonthPanel.add(yearPanel, BorderLayout.WEST);
    yearPanel.setLayout(new BorderLayout());
    yearPanel.add(yearsLabel, BorderLayout.WEST);
    yearPanel.add(yearsSpinner, BorderLayout.CENTER); monthsLabel = new JLabel("月: ");
    monthsComboBox = new JComboBox();
    for (int i = 1; i <= 12; i++) {
    monthsComboBox.addItem(new Integer(i));
    }
    monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH));
    monthsComboBox.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent actionEvent) {
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex());
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar
    .set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day);
    updateView();
    }
    });
    JPanel monthPanel = new JPanel();
    yearMonthPanel.add(monthPanel, BorderLayout.EAST);
    monthPanel.setLayout(new BorderLayout());
    monthPanel.add(monthsLabel, BorderLayout.WEST);
    monthPanel.add(monthsComboBox, BorderLayout.CENTER); daysModel = new AbstractTableModel() {
    public int getRowCount() {
    return 7;
    } public int getColumnCount() {
    return 7;
    } public Object getValueAt(int row, int column) {
    if (row == 0) {
    return getHeader(column);
    }
    row--;
    Calendar calendar = (Calendar) MyCalendar.this.calendar.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1;
    int index = row * 7 + column;
    int dayIndex = index - moreDayCount + 1;
    if (index < moreDayCount || dayIndex > dayCount) {
    return null;
    } else {
    return new Integer(dayIndex);
    }
    }
    }; daysTable = new CalendarTable(daysModel, calendar);
    daysTable.setCellSelectionEnabled(true);
    daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); daysTable.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mouseClicked(java.awt.event.MouseEvent e) {
    if (e.getClickCount() == 2) {
    Object o = daysTable.getValueAt(daysTable.getSelectedRow(),
    daysTable.getSelectedColumn());
    if (o != null) {
    // 不是点在空的格子,赋值
    value = yearsSpinner.getValue()
    + monthsComboBox.getSelectedItem().toString()
    + o;
    System.out.println(value);
    } else {
    // 否则清空
    value = "";
    } }
    }
    });
    daysTable.setDefaultRenderer(daysTable.getColumnClass(0),
    new TableCellRenderer() {
    public Component getTableCellRendererComponent(
    JTable table, Object value, boolean isSelected,
    boolean hasFocus, int row, int column) {
    String text = (value == null) ? "" : value.toString();
    JLabel cell = new JLabel(text);
    cell.setOpaque(true);
    if (row == 0) {
    cell.setForeground(headerForeground);
    cell.setBackground(headerBackground);
    } else {
    if (isSelected) {
    cell.setForeground(selectedForeground);
    cell.setBackground(selectedBackground);
    } else {
    cell.setForeground(foreground);
    cell.setBackground(background);
    }
    } return cell;
    }
    });
    updateView(); cPane.add(daysTable, BorderLayout.CENTER);
    } public static String getHeader(int index) {
    switch (index) {
    case 0:
    return WEEK_SUN;
    case 1:
    return WEEK_MON;
    case 2:
    return WEEK_TUE;
    case 3:
    return WEEK_WED;
    case 4:
    return WEEK_THU;
    case 5:
    return WEEK_FRI;
    case 6:
    return WEEK_SAT;
    default:
    return null;
    }
    } public void updateView() {
    daysModel.fireTableDataChanged();
    daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),
    calendar.get(Calendar.WEEK_OF_MONTH));
    daysTable.setColumnSelectionInterval(
    calendar.get(Calendar.DAY_OF_WEEK) - 1, calendar
    .get(Calendar.DAY_OF_WEEK) - 1);
    } public static class CalendarTable extends JTable {
    private Calendar calendar; public CalendarTable(TableModel model, Calendar calendar) {
    super(model);
    this.calendar = calendar;
    } public void changeSelection(int row, int column, boolean toggle,
    boolean extend) {
    super.changeSelection(row, column, toggle, extend);
    if (row == 0) {
    return;
    }
    Object obj = getValueAt(row, column);
    if (obj != null) {
    calendar.set(Calendar.DAY_OF_MONTH, ((Integer) obj).intValue());
    }
    } } public static void main(String[] args) {
    JFrame frame = new JFrame("Calendar Application");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    MyCalendar myCalendar = new MyCalendar();
    myCalendar.init();
    frame.getContentPane().add(myCalendar);
    frame.setSize(240, 172);
    frame.show(); }}
      

  2.   

    声明一个接口,弄一个setDateString()方法,传到这里来,点击的时候,就给这个对象传楼上的System.out.println()中的String.需要使用这个日期的就实现这个接口.
      

  3.   

    你在里面加入一行代码    public static class CalendarTable extends JTable { 
         private Main frame;
            private Calendar calendar; 
            public CalendarTable(TableModel model, Calendar calendar,Main frame) { 
                super(model); 
                this.calendar = calendar; 
                this.frame = frame;
            } 
            public void changeSelection(int row, int column, boolean toggle, boolean extend) { 
                super.changeSelection(row, column, toggle, extend); 
                if (row == 0) { 
                    return; 
                } 
                Object obj = getValueAt(row, column); 
                if (obj != null) { 
                    calendar.set(Calendar.DAY_OF_MONTH, ((Integer)obj).intValue()); 
                } 
                //==========加入以下代码===================
                JOptionPane.showMessageDialog(frame.cPane, frame.yearsSpinner.getValue()+"-" +frame.monthsComboBox.getSelectedItem()+"-"+frame.daysTable.getValueAt(frame.daysTable.getSelectedRow(),frame.daysTable.getSelectedColumn()));        } 
        } 
      

  4.   

    一般来说,这个返回的东西应该是放到一个TextField里的,所以要求传一个TextField进来:package com.ui; import java.awt.*; 
    import java.awt.event.*; 
    import java.util.*; 
    import javax.swing.*; 
    import javax.swing.event.*; 
    import javax.swing.table.*; import sun.management.StringFlag;public class MyCalendar extends JApplet { 
    public JTextField obj = null;
        public static final String WEEK_SUN = "日"; 
        public static final String WEEK_MON = "一"; 
        public static final String WEEK_TUE = "二"; 
        public static final String WEEK_WED = "三"; 
        public static final String WEEK_THU = "四"; 
        public static final String WEEK_FRI = "五"; 
        public static final String WEEK_SAT = "六";     public static final Color background = Color.white; 
        public static final Color foreground = Color.black; 
        public static final Color headerBackground = Color.blue; 
        public static final Color headerForeground = Color.white; 
        public static final Color selectedBackground = Color.blue; 
        public static final Color selectedForeground = Color.white;     private JPanel cPane; 
        private JLabel yearsLabel; 
        private JSpinner yearsSpinner; 
        private JLabel monthsLabel; 
        private JComboBox monthsComboBox; 
        private JTable daysTable; 
        private AbstractTableModel daysModel; 
        private Calendar calendar; 
        
        public MyCalendar(JTextField o) { 
            cPane = (JPanel) getContentPane(); 
            this.obj = o;
        }     public void init() { 
            cPane.setLayout(new BorderLayout());         calendar = Calendar.getInstance(); 
            calendar = Calendar.getInstance(); 
            yearsLabel = new JLabel("年: "); 
            yearsSpinner = new JSpinner(); 
            yearsSpinner.setEditor(new JSpinner.NumberEditor(yearsSpinner, "0000")); 
            yearsSpinner.setValue(new Integer(calendar.get(Calendar.YEAR))); 
            yearsSpinner.addChangeListener(new ChangeListener() { 
                    public void stateChanged(ChangeEvent changeEvent) { 
                        int day = calendar.get(Calendar.DAY_OF_MONTH); 
                        calendar.set(Calendar.DAY_OF_MONTH, 1); 
                        calendar.set(Calendar.YEAR, ((Integer) yearsSpinner.getValue()).intValue()); 
                        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
                        calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day); 
                        updateView(); 
                    } 
                });         JPanel yearMonthPanel = new JPanel(); 
            cPane.add(yearMonthPanel, BorderLayout.NORTH); 
            yearMonthPanel.setLayout(new BorderLayout()); 
            yearMonthPanel.add(new JPanel(), BorderLayout.CENTER); 
            JPanel yearPanel = new JPanel(); 
            yearMonthPanel.add(yearPanel, BorderLayout.WEST); 
            yearPanel.setLayout(new BorderLayout()); 
            yearPanel.add(yearsLabel, BorderLayout.WEST); 
            yearPanel.add(yearsSpinner, BorderLayout.CENTER);         monthsLabel = new JLabel("月: "); 
            monthsComboBox = new JComboBox(); 
            for (int i = 1; i <= 12; i++) { 
                monthsComboBox.addItem(new Integer(i)); 
            } 
            monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH)); 
            monthsComboBox.addActionListener(new ActionListener() { 
                    public void actionPerformed(ActionEvent actionEvent) { 
                        int day = calendar.get(Calendar.DAY_OF_MONTH); 
                        calendar.set(Calendar.DAY_OF_MONTH, 1); 
                        calendar.set(Calendar.MONTH, monthsComboBox.getSelectedIndex()); 
                        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
                        calendar.set(Calendar.DAY_OF_MONTH, day > maxDay ? maxDay : day); 
                        updateView(); 
                    } 
                }); 
            JPanel monthPanel = new JPanel(); 
            yearMonthPanel.add(monthPanel, BorderLayout.EAST); 
            monthPanel.setLayout(new BorderLayout()); 
            monthPanel.add(monthsLabel, BorderLayout.WEST); 
            monthPanel.add(monthsComboBox, BorderLayout.CENTER);         daysModel = new AbstractTableModel() { 
                    public int getRowCount() { 
                        return 7; 
                    }                 public int getColumnCount() { 
                        return 7; 
                    }                 public Object getValueAt(int row, int column) { 
                        if (row == 0) { 
                            return getHeader(column); 
                        } 
                        row--; 
                        Calendar calendar = (Calendar) MyCalendar.this.calendar.clone(); 
                        calendar.set(Calendar.DAY_OF_MONTH, 1); 
                        int dayCount = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 
                        int moreDayCount = calendar.get(Calendar.DAY_OF_WEEK) - 1; 
                        int index = row * 7 + column; 
                        int dayIndex = index - moreDayCount + 1; 
                        if (index < moreDayCount || dayIndex > dayCount) { 
                            return null; 
                        } else { 
                            return new Integer(dayIndex); 
                        } 
                    } 
                };         daysTable = new CalendarTable(daysModel, calendar); 
            daysTable.setCellSelectionEnabled(true); 
            daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
            daysTable.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent e) {
                
                    if (e.getClickCount() == 2) {
                        Object o = daysTable.getValueAt(daysTable.getSelectedRow(),
                                daysTable.getSelectedColumn());
                        if (o != null) {
                            // 不是点在空的格子,赋值
                           String value = yearsSpinner.getValue()
                                    + monthsComboBox.getSelectedItem().toString()
                                    + (o.toString().length()>1?o.toString():"0"+o.toString());
                            obj.setText(value);
                        }
                    }
                }
            });        daysTable.setDefaultRenderer(daysTable.getColumnClass(0), new TableCellRenderer() { 
                    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, 
                                                                  boolean hasFocus, int row, int column) { 
                        String text = (value == null) ? "" : value.toString(); 
                        JLabel cell = new JLabel(text); 
                        cell.setOpaque(true); 
                        if (row == 0) { 
                           cell.setForeground(headerForeground); 
                            cell.setBackground(headerBackground); 
                        } else { 
                            if (isSelected) { 
                                cell.setForeground(selectedForeground); 
                                cell.setBackground(selectedBackground);
                                
                            } else { 
                                cell.setForeground(foreground); 
                                cell.setBackground(background);
                            } 
                        } 
                        return cell; 
                    } 
                }); 
            updateView();         cPane.add(daysTable, BorderLayout.CENTER); 
        }     public static String getHeader(int index) { 
            switch (index) { 
            case 0: 
                return WEEK_SUN; 
            case 1: 
                return WEEK_MON; 
            case 2: 
                return WEEK_TUE; 
            case 3: 
                return WEEK_WED; 
            case 4: 
                return WEEK_THU; 
            case 5: 
                return WEEK_FRI; 
            case 6: 
                return WEEK_SAT; 
            default: 
                return null; 
            } 
        }     public void updateView() { 
            daysModel.fireTableDataChanged(); 
            daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH), 
                                              calendar.get(Calendar.WEEK_OF_MONTH)); 
            daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK) - 1, 
                                                calendar.get(Calendar.DAY_OF_WEEK) - 1); 
        } 
        public static class CalendarTable extends JTable { 
            private Calendar calendar; 
            public CalendarTable(TableModel model, Calendar calendar) { 
                super(model); 
                this.calendar = calendar; 
            } 
            public void changeSelection(int row, int column, boolean toggle, boolean extend) { 
                super.changeSelection(row, column, toggle, extend); 
                if (row == 0) { 
                    return; 
                } 
                Object obj = getValueAt(row, column); 
                if (obj != null) { 
                    calendar.set(Calendar.DAY_OF_MONTH, ((Integer)obj).intValue()); 
                } 
            } 
        }     public static void main(String[] args) { 
            JFrame frame = new JFrame("Calendar Application"); 
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            JTextField f =new JTextField(); 
            MyCalendar myCalendar = new MyCalendar(f); 
            myCalendar.init(); 
            frame.getContentPane().add(f);
            frame.getContentPane().add(myCalendar); 
            frame.setSize(240, 172); 
            frame.show(); 
        } 
    }
      

  5.   

    daysTable.addMouseListener(new MouseAdapter(){ @Override
    public void mouseClicked(MouseEvent e) {
    if(e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2){
    int selectedColumn = daysTable.getSelectedColumn();
    int selectedRow = daysTable.getSelectedRow();
    System.out.println("=================" + selectedColumn + " " + selectedRow);
    Object day = daysTable.getValueAt(selectedRow, selectedColumn);
    Object year = yearsSpinner.getValue();
    Object month = monthsComboBox.getSelectedItem();
    if(day != null){
    System.out.println("date : " + year + "-" + month + "-" + day);
    }

    }
    }

    });