File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes MouseEvent (mousePressed and mouseReleased) only works from left to right? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MouseEvent (mousePressed and mouseReleased) only works from left to right?" Watch "MouseEvent (mousePressed and mouseReleased) only works from left to right?" New topic
Author

MouseEvent (mousePressed and mouseReleased) only works from left to right?

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi all

First of all Happy Holidays to everyone!! I have a question regarding a MousEvent, i have a small Graphics program where i draw some simple shapes and am using the MouseEvent for the beginning and end posistion. But it seem after using some System.out.println()'s that it is only picking up the mouseReleased when i go to the right and down, but nothing when i go to the left or up? I am appearently missing something or there is another method i can use instead?



thanks for any help in advance!!
Mike
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

indeed you are. it isnt really the mouse events but what drawRectangle and drawOval and such require. i probably shouldn't just give you the answer but i will anyway


SCJP
Visit my download page
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi Randall,

Thanks for the help, I will have to read over that some more to understand it still.And try it with my code once i get it ;)

Thanks
Mike
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

just call that private method before you draw your shape i did a project that started out just like yours. that's how i know. i would post the whole thing but why spoil your fun
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi ,

I have it working thanks allot!! The only problem with this is when drawing a straight line it won't work. I am working on how to do that now. I have another question regarding this program and the question is, In Photoshop for instance when i am drawing a shape i will get the broken line marking the area when the left mouse button is clicked , until i release it and then it is gone and the shape is there.This helps to see exactly where the shape will end up. Is this something that also has to be done with a mouseEvent or is it part of the Operating system i am using and just need to utilize this in the OS?

Also, in Photoshop the shapes are each thier own (JPanel? i think), so you can move it around and resize it, is this also possible in Java?

Thanks
Mike
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4638
    
    5

mike ryan wrote:Is this something that also has to be done with a mouseEvent or is it part of the Operating system i am using and just need to utilize this in the OS?

You have to code it yourself, and you'll likely need to familiarize yourself with BasicStroke and setStroke(...).


luck, db
There are no new questions, but there may be new answers.
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Thank you Daryll!

I will read up on the BasicStroke.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

what i did was start with a homework that was just like you are doing now. you are correct in that you deal with drawLine differently than with drawRectangle or drawOval. it is actually easier. you dont have to call the method. just use the starting and ending x and y. i also didn't like how the program waited until i released the mouse before it drew and stored the shape. so i changed that so it draws the shape on mouseDragged and only stores it on mouseReleased. it will be more fun if you figure this out by yourself(at least i had fun improving it). if you really get stuck i will post my whole program. i am just looking for a reason to "show it off" hehe

i also improved it further using Graphics2d methods to turn antialiasing on and also to setStroke.
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi Randall,

You are correct i am doing homework however the "Homework" part i already have done, but this course is older and i also like to do some extra methods and things to just make it work more like i would like it too;) I actually had started trying to use the mouseDragged event as it just seemed to make sense, but i haven't got it working yet.I also agree that it is fun working things out on your own(as long as it doesn't give me a heart attack ), but sometimes i get stuck and then i ask questions here ;)
The Graphics2D methods look cool as well but i will have to do some testing with that still.

Thanks
Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MouseEvent (mousePressed and mouseReleased) only works from left to right?