Why does the Java doClick() use 68 milliseconds when it calls doClick(pressTime)?
Asked Answered
R

2

13

In doClick() when it calls doClick(pressTime) does it send 68 milliseconds? Why did they decide on 68 instead of a more round number? Is it a completely arbitrary number?

From Java AbstractButton:

public void doClick() {
    doClick(68);
}
Raines answered 15/6, 2016 at 15:27 Comment(3)
This is an interesting question, although I'm not sure it's necessarily answerable (because it is an apparent arbitrary decision without a comment left in the source code). I'm not familiar with AWT's internals though, so there might be a reason someone more familiar with it can provide that I'm not seeing.Aide
I would not be surprised if it is arbitrary, but if there is a reason that'd be nice to know!Raines
I am interested as well--The internals and design decisions behind the Java API and JVM are a great personal interest to me.Aide
P
6

It might have to do with how fast a human can click on average.

If you look at this timer, with a bit of excersise it's possible to reach the 68ms on average.

They might have simply made a setup like below, had a go at it to get on a nice average click duration and then used that for the default value.

var timer = 0;
var results = [];
$('#clicktest').on('mousedown',function() {
    timer = window.performance.now();
});
$('#clicktest').on('mouseup',function() {
    results.push(window.performance.now()-timer);
    var total = 0;
    for(c=0;c<results.length;c++) {
        total+= results[c];
    }
    $('#output').text('Average click duration '+ Math.round(total/results.length)+'ms');
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="clicktest">Click me</button>
<div id="output">Average click duration N/A</div>
Premolar answered 15/6, 2016 at 16:0 Comment(0)
F
1
  • note most of painting artefacts are valid for Metal L&F just and only as a defaults, f.e. Windows L&F totally ignores that, it hasn't this method as peer or returns for programing languages thats runs from Win session,

  • doClick is programatically to simulating the JButton press e.g. from mouse or key event (TAB , ENTER)

  • doClick(int pressTime) to visually paints action as information to user, painting isPressed to the screen, miliseconds from JVM returns me very closely number (1999 - 2001 for doClick(2000))

  • very low number at 68miliseconds haven't any screen effect, because isn't catchable by humans eyes, maybe most of LCD / LED monitors can't repaint this painting artefact correctly,

  • answer by @Michael Dibbets is closer to setMultiClickThreshhold(long threshhold),

Fluecure answered 16/6, 2016 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.