java gregorian calendar timer
- by Ieyasu Sawada
I have this java program which calculates the time that the person took to respond to the confirm dialog box. But it seems that both time1 and time 2 gets the same value. What have I done wrong here:
import javax.swing.JOptionPane;
import java.util.*;
public class DialogTimer{
public static void main(String args[]){
int time1, time2, milli1, milli2, sec1, sec2, timeDifference;
final int MILLISECSINSECOND =1000;
JOptionPane.showConfirmDialog(null, "Is stealing ever justified? ");
GregorianCalendar before=new GregorianCalendar();
GregorianCalendar after= new GregorianCalendar();
milli1=before.get(GregorianCalendar.MILLISECOND);
milli2=after.get(GregorianCalendar.MILLISECOND);
sec1=before.get(GregorianCalendar.SECOND);
sec2=after.get(GregorianCalendar.SECOND);
time1=MILLISECSINSECOND * sec1 + milli1;
time2=MILLISECSINSECOND * sec2 + milli2;
//timeDifference=time1 - time2;
System.out.println(time1);
System.out.println(time2);
//JOptionPane.showMessageDialog(null, "It took " + (time1 - time2) + " milliseconds for you to answer");
}
}