我正在创建一个员工假释系统,其中包括接受加入日期。
我正在使用swings在java中创建一个接口。我希望用户在日期中设置微调器的值,程序必须能够获得用户选择的日期和年份。
我的员工对象包含一个由我创建的Date类变量。
我希望在用户单击提交按钮时创建员工对象。
我无法找到解决方案。
以下是我的计划的几个片段。
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;
}
}
答案 0 :(得分:2)
我想你想要:
@Override
public void actionPerformed(ActionEvent arg0) {
Employee emp=new Employee();
emp.setDOJ(sp.getDate());//changed to getDate as setDOJ accepts Date parameter
}
根据文档:
返回此日期序列中的当前元素。这个方法是 相当于
(Date)getValue
。
注意,返回的Date
对象并未引用您自己的自定义Date
课程,而是引用java.util.Date