0

I am trying to figure out a interesting visual incongruity with awt buttons. The below code will open a window with a button. If you click on that button rapidly without moving your mouse you will see the button presses and depresses slower than your clicks. However if you move your mouse around while rapidly clicking on the button it will press and depress as quick as you click.

I cant seam to find anything about this visual difference online. Mostly just post saying "don't use awt and use swift instead". I am not interesting in what the "better" GUI library is but rather what is causing this visual difference.

Can someone explain to me why the button appears to behave differently when them mouse is not moving verses when it is moving?

import java.awt.*;
import java.awt.event.*;

public class TestApp extends Frame implements WindowListener {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private Button btn1;



    public TestApp () {
      setLayout(new FlowLayout());
      btn1 = new Button("Click ME!");
      add(btn1);
      setSize(80, 80);
      setVisible(true);

      addWindowListener(new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
              System.exit(0);
           }
       }
  );

}

   public static void main(String[] args) {
       new TestApp();
   }


}
Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
  • If this was 1996 / 1997 people might care. Join us in the 3rd millennium! Or to put that another way.. Why use AWT? See [this answer](http://stackoverflow.com/questions/6255106/java-gui-listeners-without-awt/6255978#6255978) for many good reasons to abandon AWT components in favor of Swing. – Andrew Thompson May 30 '18 at 11:15
  • @AndrewThompson As I stated in my question I am not interested in what the better option is. That is not what my question is. At the moment I am unable to add something like FX to my work PC due to administrative restrictions so for the time being I am forced to use AWT and Swing while learning Java. I already know Swing's buttons do not have this visual oddity. I am interested in what could cause something like this. – Mike - SMT May 30 '18 at 12:07
  • *"I am interested in what could cause something like this."* Well, all the best with that. But you asked on a public forum, so thought I should warn you why others .. might *not* be interested in helping. – Andrew Thompson May 30 '18 at 12:19
  • @AndrewThompson Thanks for the warning. I already assumed I would get little feed back due to the question being related to AWT. That said it is an interesting oddity so I figured it was worth asking on here. – Mike - SMT May 30 '18 at 13:07

0 Answers0