1

我有一个操作按钮,应该在登录期间检查应用程序的过期日期:

public void actionPerformed(ActionEvent ae) {
  Calendar expiredate = Calendar.getInstance();
  expiredate.set(2012, 10, 10);
  if (ae.getSource() == button) {
    char[] temp_pwd = t_pass.getPassword();
    String pwd = null;
    pwd = String.copyValueOf(temp_pwd);

    if (db.checkLogin(t_name.getText(), pwd)) {
      try {
        if (Calendar.getInstance().after(expiredate)) {
          JOptionPane.showMessageDialog(null, "License has Expired\n Please Re-new the License from the Provider", "Re-new License", JOptionPane.ERROR_MESSAGE);
          t_name.setText("");
          t_pass.setText("");
          t_name.requestFocus();
          return;
        }
        JOptionPane.showMessageDialog(null, "You have logged in successfully. Click OK to Continue", "Success",
        JOptionPane.INFORMATION_MESSAGE);
        MainFrame page = new MainFrame();
        page.setVisible(true);
        setVisible(false);
      } catch(Exception ai){
        JOptionPane.showMessageDialog(null, ai, "Exception",
        JOptionPane.INFORMATION_MESSAGE);
      }
    } else {
      JOptionPane.showMessageDialog(null, "Login failed!\nWrong Username or password", "Failed!!",
      JOptionPane.ERROR_MESSAGE);
      t_name.setText("");
      t_pass.setText("");
      t_name.requestFocus();
      return;
    }
  }//if
}//method

问题是系统日期是 2012 年 10 月 17 日。显然登录仍然发生。但是当我将 2012 更改为 2011 作为到期日期时,就会发生许可证验证。系统忽略 2012 年 10 月 10 日日期可能是什么问题?

4

2 回答 2

5

月份常数10为 11 月。NOVEMBER = 10所以你将月份设置为 11 月。

你应该使用

expiredate.set(2012, Calendar.OCTOBER, 10);

始终使用Calendar中提供的月份常量进行此类使用,因为月份从0java 中开始。所以它避免了混乱。

于 2012-10-17T09:04:06.033 回答
1

问题是,日历的月份值是从 0 开始的。这意味着,您的过期日期是 11 月 10 日。

10 月 10 日将是:

expiredate.set(2012, 9 , 10);

希望这有帮助

于 2012-10-17T09:06:21.367 回答