This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes MousePressed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MousePressed" Watch "MousePressed" New topic
Author

MousePressed

Chris Roberts
Greenhorn

Joined: Sep 03, 2004
Posts: 8
I was trying to get my MousePressed method to detect that I clicked on the
screen. When I click on the screen a circle is supposed to appear and be placed inside of a vector. How can I go about detecting this event in my code.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Add your mouse listener to your JPanel (that does the drawing) in it's constructor. The constructor is the place to build and initialize variables for your class. I am still using j2se 1.4 so am unable to use the generic form of the Storage vector; thus the declaration of shapes. I made up a Circle class that would allow the code to compile. The general idea in drawing, though you are free to do things any way you want, is to add the Circles to the vector in the mouse code and draw them in the rendering component (the JPanel DP below). I changed the names to avoid name–clashing in your VM.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MousePressed
 
Similar Threads
Handling scrollpanes
repainting
Problem with simple drawing tool
Mouse events
Graphics 2d Object and Scroll Bar Issue