Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从SPinnerDateModel的Jspinner获取日期_Java_Swing_Date_Actionlistener_Jspinner - Fatal编程技术网

Java 从SPinnerDateModel的Jspinner获取日期

Java 从SPinnerDateModel的Jspinner获取日期,java,swing,date,actionlistener,jspinner,Java,Swing,Date,Actionlistener,Jspinner,我正在创建一个员工假释制度,其中包括接受加入日期 我使用Swigs在java中创建一个接口。我希望用户在日期中设置微调器的值,程序必须能够获得用户选择的日期、月份和年份 我的employee对象由我创建的类日期变量组成 我希望在用户单击submit按钮时创建employee对象 我找不到解决办法 下面是我的几个程序片段 mainframe.java private JSpinner sdoj; private SpinnerDateModel sp; sp=new SpinnerDateMode

我正在创建一个员工假释制度,其中包括接受加入日期

我使用Swigs在java中创建一个接口。我希望用户在日期中设置微调器的值,程序必须能够获得用户选择的日期、月份和年份

我的employee对象由我创建的类日期变量组成

我希望在用户单击submit按钮时创建employee对象

我找不到解决办法

下面是我的几个程序片段

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
     }
}
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
    }
}
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;
    }
}
Employee.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
     }
}
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
    }
}
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;
    }
}
Date.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
     }
}
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
    }
}
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;
    }
}
我想你想要:

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

根据文件:

返回此日期序列中的当前元素。这种方法是可行的 相当于
(日期)getValue


注意:返回的
Date
对象不是指您自己的自定义
Date
类,而是指您的方法有效,但它也包含时间。是否有只获取日期而不获取日期的watime@user2625973它返回一个
Date
对象,该对象具有分别获取年、月、日以及分钟、小时和秒的方法。请参阅
java.util.Date
上答案中的最后一个链接。还可以查看mKorbels answers中的链接,该链接在只输出日期而不输出时间时使用