gpt4 book ai didi

java - 如何在java swing中弹出错误来检查酒店入住日期是否应该早于退房日期?

转载 作者:行者123 更新时间:2023-12-02 12:10:34 25 4
gpt4 key购买 nike

我有以下 jswing 应用程序的屏幕截图。 JswingDate

在这里,我这样写,从日期选择器中选择日期 -

//CheckIn Date
JDateChooser dateChooser = new JDateChooser();
dateChooser.setBounds(177, 136, 149, 22);
frame.getContentPane().add(dateChooser);

//CheckOut Date
JDateChooser dateChooser_1 = new JDateChooser();
dateChooser_1.setBounds(177, 136, 149, 22);
frame.getContentPane().add(dateChooser_1);

现在,如何编写逻辑来选择入住日期早于退房日期?如果入住日期晚于退房日期,则会弹出错误消息“入住日期应早于退房日期”

我已经使用了 Action 监听器,但无法复制。

最佳答案

Now, How to write the logic to select the Check In date earlier than Check Out date?

首先查看JavaDocs for java.util.Date ,你会发现它有很多方便的方法,特别是 beforeafter 。由此您可以根据您的需求构建简单的逻辑检查

If the Check In date is after Check Out date, an error should be popped up saying "check in date should be earlier than checkout date"

最常见的方法是使用JOptionPane,看看How to make dialogs了解更多详情

关于java - 如何在java swing中弹出错误来检查酒店入住日期是否应该早于退房日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46582237/

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