File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Event Handlers:Mouse over Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Event Handlers:Mouse over "circles"" Watch "Event Handlers:Mouse over "circles"" New topic

Event Handlers:Mouse over "circles"

Sanjit Singh

Joined: Nov 12, 2001
Posts: 27
Hi Everyone,
I am a beginner with Swing and I have to complete a project that is due soon. So I would be grateful if somebody could help me out.
I basically have a JFrame and a JPanel inside it to draw a few lines and circles. I am making a time graph inside the JPanel using raw x and y coordinates. I want to achieve the following:
1.I want to draw a small circle at the point where two lines meet.
2.I would also like to have a small pop up box with a message inside it when the user brings his mouse over this circle. I would not like to have a JOptionPane but instead a small window as I have lots of text (multiple lines)to display. When the user moves his mouse away from this circle, then the message box should close automatically.
I have already done point 1. by having a
public void paintComponent(Graphics g)
method in which I am using the graphics object to draw lines and circles.
PROBLEM: My main problem is in point 2, where I would like to add mouse listeners to this circle and somehow to implement this pop box. How can I achieve this? Can I have event handlers on a "circle" and that also inside the paintComponent method? Which swing component should I use for the popup window and how can I use it for my purpose?
Any help in this regard (sample code)would be highly appreciated. Thanks in advance!
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

Here's a short example of how to use multiple tooltips on components that generate graphics... enjoy!

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Event Handlers:Mouse over "circles"
It's not a secret anymore!