RFR: 8341982: Simplify JButton/bug4323121.java

Abhishek Kumar abhiscxk at openjdk.org
Mon Oct 14 15:27:11 UTC 2024


On Mon, 14 Oct 2024 15:00:17 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> test/jdk/javax/swing/JButton/bug4323121.java line 69:
>> 
>>> 67:             SwingUtilities.invokeAndWait(() -> {
>>> 68:                 button = new TestButton("gotcha");
>>> 69:                 button.addMouseMotionListener(eventHandler);
>> 
>> Don't think it is required anymore to add `MouseMotionListener`.
>
> I just kept it because it was there. When the event handler extends `MouseAdapter`, there are no additional methods to override.
> 
> However, you're right, `MouseMotionListener` is not needed.

Since you are simplifying the test, I guess this can be considered.

>> test/jdk/javax/swing/JButton/bug4323121.java line 70:
>> 
>>> 68:                 button = new TestButton("gotcha");
>>> 69:                 button.addMouseMotionListener(eventHandler);
>>> 70:                 button.addMouseListener(eventHandler);
>> 
>> You may get rid of `eventHandler` object (provided MouseMotionListener is not required) by adding the mouse listener similar to WindowFocusListener where you used WindowAdapter class and override WindowGainedFocus method. 
>>  
>>             button.addMouseListener(new MouseAdapter() {
>>                     @Override
>>                     public void mouseEntered(MouseEvent e) {
>>                         if (button.getModel().isArmed()) {
>>                             modelArmed = true;
>>                         }
>>                         mouseEntered.countDown();
>>                     }
>>                 });
>
> Yes, it's an option.
> 
> I used the same approach in #21474 where the test object serves as an event handler. This avoids anonymous classes which add indentation.

Yeah, this is an option. As I mentioned earlier that MouseMotionListener is not needed, so creating an eventHandler object may not be of great use. I agree if more than one listener needs to be added, creating an eventHandler object is a good idea.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21475#discussion_r1799716318
PR Review Comment: https://git.openjdk.org/jdk/pull/21475#discussion_r1799715177


More information about the client-libs-dev mailing list