JCalendarを使用した単純な Java プログラムがあります。JCalendarcalendario
が空であるかどうかを知る必要があります。これは、ユーザーが日付を選択したかどうかを意味します。のような方法を考えていましたcalendario.isEmpty
が、存在しません。比較できるかもしれませcalendario
んnull
が、うまくいきませんでした。を使用してcom.toedter.calendar.JDateChooser
います。
4767 次
2 に答える
4
を使用している場合はcom.toedter.calendar.JDateChooser
、インスタンス メソッドを呼び出して返された日付を確認するのが最善の方法getDate()
です。返された日付が の場合null
、ユーザーが日付を選択していないことを意味します。例えば:
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 is required.");
}
}
public static void main(String[] args) {
new TestCalendar().setVisible(true);
}
}
于 2014-03-24T17:29:43.503 に答える