Timestamp returned from getWhen()

Hi,

I am confused with the timestamp returned from getWhen(), while it seems that this timestamp is NOT retrieved in the same way as currentTimeMillis().

I have written a testing program, constructing an UI with only a button and adding some printout in actionPerformed:

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass PressButton{

publicstaticvoid main(String args[]){

JFrame frame =new JFrame();

frame.setSize(200,200);

final JButton button =new JButton("Click Me!");

button.addActionListener(new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

if (e.getSource() == button){

System.out.println(new Date(System.currentTimeMillis()));

System.out.println(new Date(e.getWhen()));

}

}

});

frame.getContentPane().add(button);

frame.setVisible(true);

}

}

When I run this program and press the button, both timestamps are equal. After that, I change the windows clock (say a day later) and press the button again. In this case, the timestamp returned from getWhen() is still the old day while that returned from currentTimeMillis() is a day later.

Is there a implementation difference in the JRE?

P.S. Java Version:

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)

Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

[2394 byte] By [kelvinfunga] at [2007-10-1 1:21:09]
# 1

Hi, I'm also interested in an answer to this question.

In our application we try to sort out mouse events to prevent multiple actions if a impatient user clicks a button more than once. The logic checks if the event happened before the completion of the last processed event.

We then also noticed differences in the event time to the current system time, so as if the thread creating the event object does not update the time from the system time regularly.

We use JRE 1.4.2_01

regards

Martin Purkert

Martin.Purkerta at 2007-7-8 1:38:54 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...