此处链接到GUI图像-------> http://imgur.com/uPD0K5S
public class MainMenu extends javax.swing.JFrame {
public MainMenu() {
initComponents();
cmbRoomNumber.setEnabled(false);
jPanel1.setVisible(false);
btnBook.setEnabled(false);
//SETTING COMBOBOXES TO NONE
cmbPhotoId.setSelectedIndex(-1);
cmbStayDuration.setSelectedIndex(-1);
//LABELS VALIDATION
jlblNameVer.setVisible(false);
//SETTING DATE TODAY
Date now = new Date();
//Set date format as you want
SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
this.ftxtCheckinDate.setText(sf.format(now));
}
正如您所见,我想根据在组合框中选择的天数(cmbStayDuration)添加退房日期(ftxtCheckOutDate)的天数
我正在使用netbeans JFrame
谢谢:)
private void cmbStayDurationActionPerformed(java.awt.event.ActionEvent evt) {
}
答案 0 :(得分:0)
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, combobox number);
基本上,Calendar类具有添加天数的功能。 现在获取日期,获取组合框日,然后添加它。
例如:
public static void main(String[] args) {
// TODO code application logic here
Calendar c = Calendar.getInstance();
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
c.setTime(d);
System.out.println(sdf.format(c.getTime()));
c.setTime(d);
c.add(Calendar.DATE, 10);
System.out.println(sdf.format(c.getTime()));
}
输出:
05/11/2015
15/11/2015
至于在ComboBox更改时更改Check-out Date表单的值,您可以添加ActionListener来监听它的更改。 Example