本文介绍了Java中的Interactive Map查看器桌面应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Java中构建一个桌面应用程序 - 一个地图查看器,如下所示: http://sunsite.ubc.ca/UBCMap/ 。每当有人将鼠标悬停在地图上的建筑物上时,应该有一个气球工具提示,说明地图上的建筑物,如办公室电话号码等,并且该建筑物应该在2-d地图中发光。有人可以给我一些指示,我应该在Java中使用什么框架来构建这样的东西(例如JavaFx)?是否有任何类似的示例代码?

I want to build a desktop application - a map viewer , something like this : http://sunsite.ubc.ca/UBCMap/ in Java . Whenever someone hovers the mouse over a building on the map , there should be a balloon tool-tip saying something about that building on the map like its office phone number etc and that building should glow in the 2-d map. Can someone provide me some directions as to what framework should i use in Java to build something like this(e.g JavaFx) ? Is there any sample code which does something similar ?

推荐答案

如果你真的拥有的是一个图像并且你想要工具提示 - 这是一个30秒的描述。

If really all you have is an image and you want tooltips over it - here is a 30 second description.


  • 子类JPanel

  • 覆盖paint()方法绘制图像

  • 将一些Shape对象(多边形,rects等等)定义为建筑物以及文本工具提示字符串

  • 覆盖JPanel子类中的getTooltip。在每次调用时迭代您的Shape对象,测试该点是否在内部形状(形状有一个方法)。返回适合Shape的工具提示,如果你的鼠标没有形状,则返回null

  • 如果你想要翻转效果,请注册MouseMotionListener并使用它来查找悬停形状。调用repaint()并以某种特殊方式渲染你的悬停。

  • 热潮!你已经完成了

  • Subclass JPanel
  • override paint() method to draw image
  • Define some number of Shape objects (polygons, rects, etc...) as your "buildings" along with a text tooltip string
  • override getTooltip in JPanel subclass. On each call iterate over your Shape objects, testing if the point is inside shape (shape has a method for this). return tooltip appropriate for Shape, or null if your mouse isn't over shape
  • if you want rollover effects, register MouseMotionListener and use it to find the "hover" shape. Call repaint() and render your "hover" in some special way.
  • boom! you're done

提示:你最需要用TooltipManager注册你的JPanel。

HINT: You will need to register your JPanel with TooltipManager most likely.

这篇关于Java中的Interactive Map查看器桌面应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 05:02