java日期的组合框,通过组合框向Java文本字段添加日期

LINK TO GUI IMAGE HERE -------> 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));

}

As you can see i want to add days to Check-out Date(ftxtCheckOutDate) depending on how many days selected in the combobox(cmbStayDuration)

Im using netbeans JFrame

Thanks :)

private void cmbStayDurationActionPerformed(java.awt.event.ActionEvent evt) {

}

解决方案

Calendar c = Calendar.getInstance();

c.setTime(new Date());

c.add(Calendar.DATE, combobox number);

Basically Calendar class has a function to add days.

Get the date now, get the combo box day, then add it.

For example:

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()));

}

Output:

05/11/2015

15/11/2015

As for changing the value of Check-out Date form as the ComboBox changes, you can add either an ActionListener to listen to it change.

Example

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值