I have an action button that is supposed to check the expire date for the application during login:
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
The problem is that the system date is 17th October 2012. Apparently the login still happens. But when I change the 2012 to 2011 as the Expire date, the license validation happens. What could be the issue that the system is ignoring the 10th October 2012 date?
Month constant
10is for November.NOVEMBER = 10so you are setting month as November.You should use
Always use month constants provided in Calendar for such usage because month starts from
0in java. So it avoids confusion.