Question

I am creating an employee parole system which include accepting the date of joining.

I am using swings to create an interface in java. I want the user to set the value of spinner in the date and the program must be able to obtain the day month and year selected by the user.

My employee object consists of a variable of class Date which is created by me.

I want an object of employee to be created when the user clicks the submit button.

Im unable to find the solution.

Here are a few snippets of my program.

mainframe.java

private JSpinner sdoj;
private SpinnerDateModel sp;
sp=new SpinnerDateModel();

sdoj=new JSpinner(sp);
submit.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
    Employee emp=new Employee();

    emp.setDOJ(sp.getCalendarField()); //this is something i have tried but i am not successful
     }
}

Employee.java

public class Employee {

    private int employeeId;
    private String employeeName,employeeAddress;
    private boolean bC, bCPlus,bJava;
    private EnumGender eGender;
    private EnumDepartment eDepartment;
    private EnumQualification eQualification;
    private Date DOJ;

    public Employee() {
       // TODO Auto-generated constructor stub
    }
}

Date.java

public class Date {
    private int day,month,year;

    public Date(int day, int month, int year) {
        super();
        this.day = day;
        this.month = month;
        this.year = year;
    }
}
Was it helpful?

Solution

I think you want:

@Override
public void actionPerformed(ActionEvent arg0) {
    Employee emp=new Employee();
    emp.setDOJ(sp.getDate());//changed to getDate as setDOJ accepts Date parameter
}

SpinnerDateModel#getDate()

As per docs:

Returns the current element in this sequence of Dates. This method is equivalent to (Date)getValue.

NB the Date object returned does not refer to your own custom Date class but rather the java.util.Date

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top