问题描述
我正在用 Java 为待办事项列表制作 GUI,我想在文件中编写一个待办事项类型对象。待办事项对象具有名称、描述和确定要完成的日期。使用 GUI,用户可以添加任意数量的待办事项对象并将其写入文件。我无法使用 getText() 从 JTextField 获取用户的日期并在 LocalDate 类型对象中解析它以便写入文件。
我现在正在运行的代码:
//注册方式
public void RegularObligationRegister(RegularObligations R) throws IOException {
try {
objOutObligations.writeObject(R);
JOptionPane.showMessageDialog(null,"Save Success");
System.out.println(R);
objOutObligations.flush();
} catch (FileNotFoundException ex) {
System.out.println("Error with specified file . . .");
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
//actionperformed方法
@Override
public void actionPerformed(ActionEvent ae) {
.
.
.
if (ae.getSource().equals(REntryObligationSave)) {
RegularObligations R = new RegularObligations(RegularEntry_TextObligationName.getText(),RegularEntry_TextObligationDescription.getText(),LocalDate.parse(RegularEntry_TextObligationDeadline.getText()));
try {
this.RegularObligationRegister(R);
} catch (IOException ex) {
Logger.getLogger(GUI.class.getName()).log(Level.SEVERE,null,ex);
}
RegularEntry_TextObligationName.setText(null);
RegularEntry_TextObligationDescription.setText(null);
RegularEntry_TextObligationDeadline.setText(null);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)