0

This is my code for Datespinner

//DateOfBirth{
    DateOfBirth = new JLabel("Date Of Birth (MM/DD/YYYY): ");
    DateOfBirth.setBounds(50,490,180,20);
    jpanel.add(DateOfBirth);

    Date date1 = new Date();
    dobmodel = new SpinnerDateModel(date1,null,null,Calendar.YEAR);
    dobspinner = new JSpinner(dobmodel);
    JSpinner.DateEditor ded = new JSpinner.DateEditor(dobspinner,"MM/dd/yyyy");
    dobspinner.setEditor(ded);
    dobspinner.setBounds(250, 490, 125, 20);
    jpanel.add(dobspinner);

    //I used a ChangeListener


    dobspinner.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e1) {
           int DateOfBirth1 = (int) ((JSpinner) e1.getSource()).getValue();
        }

        public void stateChanged1(ChangeEvent arg01) {

        }
    });

But I am getting the following error:

java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.Integer.

What should i do? I am stuck.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720

1 Answers1

1

The method getValue() would return a Date object, so you should cast Date rather than int on that and change the type of DateofBirth1 to Date.

David
  • 3,957
  • 2
  • 28
  • 52