• Post Reply Bookmark Topic Watch Topic
  • New Topic

graphics  RSS feed

 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wanted to make a car class. Various different cars so it extends vehicle. I want a JFrame and a JPanel or JComponent in the center of it.

I think i need to extend JCoponent on vehicle so it has tooltips
public class Vehicle extends JComponent{}

but when i override JPanel and create vehicle objects by overriding paintComponent(Graphics){} it does display tooltips when viewing the JFrame that the JPanel is added to.

i think the add() method is only way to use tooltips not paint methods but...
How can i make a Shape object with tooltips than???
roba
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Component approach. Using a JComponent to draw your car on will show the shape of the car with a non–opaque (transparent) background. Using the built–in JComponent tooltip will show the tooltip after the mouse enters the JComponent boundry. To have the tooltip show only after crossing the boundry of the graphic shape drawn on the JComponent you will have to write some creative code. You could put this code in a superclass such as Vehicle. Use a MouseMotionAdapter/Listener for each JComponent and show the tooltip after crossing the boundry of the shape (mouseMoved).
Graphic approach. Draw your vehicles on and add the MouseMotionAdapter/Listener to the JPanel that draws the shapes. Your mouse(Moved) code will monitor all drawn shapes for penetration.
Be careful with mouseMoved code; it's easy to do too much in the method.
For some implementation ideas: tooltip-like popup with mouseover.
There are a lot of ways to put these kinds of things together so let your imagination be active.
 
rob armstrong
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow looks like you did my homework for me! I really appreciate that link! I was kinda using the adapter method already so i was closing in on the concept but this will help me out alot.
Thanks
roba
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!