我想创建一个显示城市地图的简单 GUI 应用程序。
然后,我想以编程方式将酒店、餐馆等项目(资产)作为图像添加到此地图中。
伪代码如下
[set up background object with map image covering entire form]
[create hotel1 object (image, label with icon or whatever]
hotel1.image = "hotel.png";
hotel1.size-x = 30;
hotel1.size-y = 30;
hotel1.location-x = 450; (pixels)
hotel1.location-y = 300;
background-object.add(hotel1);
[create restaurant1 object (image, label with icon or whatever]
restaurant1 .image = "hotel.png";
restaurant1 .size-x = 30;
restaurant1 .size-y = 30;
restaurant1 .location-x = 600; (pixels)
restaurant1 .location-y = 400;
background-object.add(restaurant1);
[repeat for hotel2, hotel3, restaurant2 etc...]
这样我就可以向地图添加任意数量的资产。我需要的其他功能是
更改资产的图像(例如,为资产显示不同的图像)
hotel1.image = "hotel_closed.png";
重叠资产(如果它们靠近)
- 为每个资产注册一个点击事件处理程序
- 更改资产的可见性
hotel1.visible = false;
我是一位经验丰富的.Net 程序员。这项任务在 .Net 中将是一项简单的任务,但是我不清楚在 Java 中完成上述任务的最佳方法。请有人建议实现上述目标的最佳方法。如果提出一个概念,我很高兴谷歌(我不需要完整的编码解决方案!!)
非常感谢,伊恩