This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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?
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.
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.