gpt4 book ai didi

java - 从 SPinnerDateModel 的 Jspinner 获取日期

转载 作者:行者123 更新时间:2023-11-30 04:17:29 25 4
gpt4 key购买 nike

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

我正在使用 swings 在 java 中创建一个界面。我希望用户在日期中设置微调器的值,并且程序必须能够获取用户选择的年月日。

我的员工对象由我创建的 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
}
}

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
}
}

日期.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;
}
}

最佳答案

我想你想要:

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

SpinnerDateModel#getDate()

根据文档:

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

注意,返回的 Date 对象并不引用您自己的自定义 Date 类,而是引用 java.util.Date

关于java - 从 SPinnerDateModel 的 Jspinner 获取日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17978527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com