Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching a mouse click.

Status
Not open for further replies.

thebarslider

Programmer
Dec 21, 2001
80
GB
I am using Java2 with OpenGl to draw a triangle of vertices red, blue and green. I want to be able to press R and then click on the applet to resize the red vertex of my triangle. So far i have a KeyListener and a MouseListener but so far i have to click then press a key to resize the triangle. I want to be able to press a key then click to resize the triangle. How do i make the program wait for a mouse event before drawing the triangle?

case KeyEvent.VK_R:
message = "Set Red Vertex with Mouse";

// I want to get the program to wait for a mouse event at this point. How do i do that?

vertex[0] = x;
vertex[1] = y;
break;

I already have the below mouseClicked method:

public void mouseClicked(MouseEvent e) {
lastClick = e.getPoint();
// gets the last click in screen coords
}

I am really quite stuck on this problem, any help would be gladly accepted.

Mark.
 
I don't think you can "make it wait" like you want. Hitting a key or clicking a mouse generates an event, and your listeners have to handle it. I think you could move the vertex set lines into the mouseClicked method, though, and just set a flag in the keyPressed method to indicate which key was pressed. Your mouseClicked method could check to see if the flag is set and, if not, do nothing.
 
I haven't checked but I am sure there would be an isClicked() or isPressed() method you could call to check whether or not a key or mouse button is being used at the time you would like to initiate your process? probably wrong though...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top