如何将actionListener添加到使用netbeans放置的现有jCalendar的jDayChooser组件中?

我只想在单击日期按钮时才触发事件。当jCalendar中的propertyChange甚至侦听jMonthChooser和jYearChooser时

附言使用toedter的jCalendar

最佳答案

或者,您可以侦听特定的propertyName"day"

JDayChooser jdc = new JDayChooser();
jdc.addPropertyChangeListener("day", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent e) {
        System.out.println(e.getPropertyName()+ ": " + e.getNewValue());
    }
});

附录:如何使它适用于JCalendar

同样,propertyName"calendar"表示一个Calendar,您可以从中对get()进行DAY_OF_MONTH
JCalendar jc = new JCalendar();
jc.addPropertyChangeListener("calendar", new PropertyChangeListener() {

    @Override
    public void propertyChange(PropertyChangeEvent e) {
        final Calendar c = (Calendar) e.getNewValue();
        System.out.println(c.get(Calendar.DAY_OF_MONTH));
    }
});

10-07 23:57