George Jacobs

Greenhorn
+ Follow
since Nov 29, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by George Jacobs

Thanks for the code. Haven't tried to implement yet, but will try soon.

My next question is how do I now calculate the coordinates of the rectangle after it is drawn. For example, I would like to know center x, y coordinates of rectangle, the four corner coordinates, and the width/height which could be derived by these listed.
13 years ago

Michael Dunn wrote:there's a bunch of things you have wrong, using old depecated methods, using paint() etc

here's a framework for you to play around with.

run it, click anywhere in the panel, drag the mouse sideways, then release it and check the console messages.



Michael, thank you so much for the help. I got the rectangle to draw, but I am not sure if it is the best way because of the repaint method. Are there any problems with repaint

13 years ago

Randall Twede wrote:no, that is not a problem just set them both to have the same mouseListener. then in your mouse handling code determine where the event came from. e.getsource(). or let the JFrame handle its and let the JPanel handle its. that might be the best way.



Thanks Randall!

I have created a class to attempt to try this, but I am having trouble getting a box to draw.

Here is my code associated with what I have done.



I had to implement all abstract methods, but the goal is to draw a rectangle with the mouselistener in the jpanel. I open the program and I get nothing besides the "Draw a box by dragging the mouse" message. What am I doing wrong?
13 years ago
Since my previous post has gotten much action I figured I would ask a more broad question.

How do I create a GUI that can have 2 mouse events on different "panes" and keep track of these? Is this doable?

For example, I have a JFrame with a mouse event and a JPanel with mouse events. Do I need to make one a keyboard event and keep the other as a mouse event?

Thanks!
13 years ago
I haven't done much Java GUI programming, but I have inherited a program that involves a Java GUI.

I am wondering how I can use a mouse event to draw a box on a GUI and then calculate the distance from the box to the mouse. I am trying to essentially combine these 2 programs together.



Program 2:


I am trying to replace the red rectangle with the user drawn box. I also don't need the box to be redrawn, but some sort of Calculate box. Does anybody know how I can do this in Java without all these conflicting mouse events? I really appreciate any help.
13 years ago