java - How to know if a JCalendar is empty? -
i have simple java program jcalendar. need know if jcalendar calendario
or not empty, means if user selected or not date. thinking method calendario.isempty
doesn't exist. maybe can compare calendario
null
didn't work. using com.toedter.calendar.jdatechooser
.
if using com.toedter.calendar.jdatechooser
, best way check returned date invoking instance method getdate()
. if returned date null
, means user has not selected date. e.g.:
public class testcalendar extends jframe implements actionlistener { private jdatechooser datechooser; public testcalendar() { super("simple"); setdefaultcloseoperation(windowconstants.exit_on_close); setlayout(new flowlayout()); datechooser = new jdatechooser(); add(datechooser); jbutton button = new jbutton("check"); button.addactionlistener(this); add(button); setsize(300, 100); } public void actionperformed(actionevent e) { date date = datechooser.getdate(); if (date == null) { joptionpane.showmessagedialog(testcalendar.this, "date required."); } } public static void main(string[] args) { new testcalendar().setvisible(true); } }
Comments
Post a Comment