0

我在摇摆中使用日历,发生错误,当我单击按钮时,如果没有选择日期,日历不会处理。假设用户未选择任何日期时如何实现处置功能。下面的代码: -

 JButton btnDate = new JButton("");
            btnDate.setBackground(Color.WHITE);
            btnDate.setBorder(null);
            btnDate.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnDate.setToolTipText(" Click to Select date");
            btnDate.setIcon(new ImageIcon(SendFile.class.getResource("/images/Calender.png")));
            btnDate.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    DatePicker dp = new DatePicker((Observer) textField, getLocale());
                    dp.setSelectedDate(new Date());
                    dp.start(textField);
                }
            });
            btnDate.setBounds(396, 230, 24, 24);
            add(btnDate);

and using class :
class ObservingTextField extends JTextField implements Observer {
        public void update(Observable o, Object arg) {
            Calendar calendar = (Calendar) arg;
            DatePicker dp = (DatePicker) o;
            System.out.println("picked=" + dp.formatDate(calendar));
            setText(dp.formatDate(calendar));
        }
    }
4

0 回答 0