简体   繁体   English

如何将JPanel放置在另一个JPanel中的指定坐标处

[英]How to place JPanel at specified coordinates within another JPanel

I am trying to create a clickable map that will draw villages based on their coordinates. 我正在尝试创建一个可点击的地图,该地图将根据其坐标绘制村庄。 However, they have to be selected by mouse click. 但是,必须通过单击鼠标来选择它们。 The villages are connected via roads and Gnomes are traveling across them as individual threads. 村庄通过公路连接,侏儒作为单独的线程穿越它们。 Therefore I currently have two problems, of which only the first one fit the title: 因此,我目前有两个问题,其中只有第一个适合标题:

  1. How do I create JPanels for each village and then place them at a specific coordinate within another JPanel 如何为每个村庄创建JPanel,然后将它们放置在另一个JPanel中的特定坐标处

  2. How do I constantly repaint the villages, gnomes, and roads while simultaneously listening for mouse clicks and allowing for various creation modes? 如何不断重绘村庄,地精和道路,同时听取鼠标单击并允许各种创建模式?

Some extra info: 一些额外的信息:

  • A click on the map in village creation mode creates a new village 在村庄创建模式下单击地图可创建一个新村庄
  • A click on a village will allow the option to delete it 单击村庄将允许您选择删除它
  • Clicks on two villages will connect them with a road. 点击两个村庄将使它们与道路相连。
  • Check out the GraphPanel example by @trashgod which allows you to create nodes of different shapes. 退房GraphPanel通过@trashgod例子,您可以创建不同形状的节点。

    You can then use "shift click" to select multiple nodes and then use the context menu (right clicking) to connect the nodes and draw a line between the two. 然后,您可以使用“ Shift Click”来选择多个节点,然后使用上下文菜单(右键单击)来连接节点并在两个节点之间画一条线。 You can also use the context menu to delete any node. 您也可以使用上下文菜单删除任何节点。

    I have no idea how to have the gnomes travel along the roads, but it should be a start for you. 我不知道如何让侏儒沿着马路行驶,但这应该是您的起点。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM