difference between mouseReleased and mouseClicked
Asked Answered
S

3

5

searching on the JAVA api document, i knew the difference between the mousePressed and mouseClicked. but.. the mouseClicked method involves both pressing and releasing so the action is done after the releasing the mouse, i don't find much difference with mouseReleased.

when i tried myself, i found that pressed and clicked are different because the time of action is different, but it's not the case between clicked and released.

my program is about drawing oval at the selected point in canvas

i'm looking for help in this problem.

Schlosser answered 12/6, 2018 at 8:57 Comment(0)
M
5

There is not a very big difference, but mouseClicked happens when:

Invoked when the mouse button has been clicked (pressed and released) on a component.

Instead mouseReleased:

Invoked when a mouse button has been released on a component.

So if you click outside your application, drag the mouse on the application and release it you have a mouseReleased event, but you don't have a mouseClicked event, because it was pressed outside the application.

Matins answered 12/6, 2018 at 9:3 Comment(2)
Isn't your last paragraph indicating a big difference?K2
its like he said, if u drag to far (whether or not its off the application enitrely) mouseReleased gets called after mouseDragged; mouseClicked doesntSometime
F
1

mouseClicked work when you press and release the mouse button in the same coordinates, obviously inside the JComponent.
mousePressed work as soon as press the mouse button in the JComponent.
mouseReleased work as soon as release the mouse button, provided that has previously press in the JComponent.

While you press the mouse button in the JComponent, no matter the final coordinate for to release the mouse button, it could even be outside the JComponent.
In all cases no matter the length of time between pressing and releasing.

HCL from Perú

Fluecure answered 30/5, 2020 at 20:21 Comment(0)
S
0

MouseDragged, generated when the user moves the mouse while holding down a mouse button;

MouseReleased, generated when the user releases one of the buttons on the mouse;

void mouseReleased(MouseEvent e)

Invoked when a mouse button has been released on a component.

Splendiferous answered 3/3, 2022 at 6:20 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Diaphaneity

© 2022 - 2024 — McMap. All rights reserved.