简体   繁体   English

在Java中显示HTML并与之交互

[英]Displaying and interacting with HTML within Java

I have a problem which I am currently trying to wrap my head around, and any advice or nods in a good direction would be greatly appreciated. 我目前有一个问题想解决,请大家多多指教。

  1. I want to display a Google Map within my Java Swing project, (the map will be a URL specified within an HTML document I think). 我想在我的Java Swing项目中显示一个Google Map(该地图将是我认为在HTML文档中指定的URL)。

  2. I also want to be able to communicate and interact with the map using JavaScript, injected via buttons in java swing, etc. So for example, I could have java buttons 'Satellite', 'Hybrid', and 'Earth' next to the map, and clicking them would perform the corresponding javascript action on the map. 我还希望能够使用JavaScript与地图进行通信和交互,并通过Java swing中的按钮注入等。因此,例如,我可以在地图旁边放置Java按钮“卫星”,“混合”和“地球” ,然后点击它们将在地图上执行相应的javascript操作。 JavaScript methods would probably already be created within the HTML file (such as 'switchToSatelliteMap'), it would just be a matter of calling them within Java. JavaScript方法可能已经在HTML文件(例如“ switchToSatelliteMap”)中创建了,这只是在Java中调用它们的问题。

Thanks in advance for any help whatsoever, 预先感谢您的任何帮助,

tre. tre。

I don't know whether this answers your question at all, but I think you will find these links helpful: 我不知道这是否完全可以回答您的问题,但是我认为您会发现这些链接有用:

  1. http://today.java.net/article/2007/10/24/building-maps-your-swing-application-jxmapviewer http://today.java.net/article/2007/10/24/building-maps-your-swing-application-jxmapviewer
  2. http://swinglabs.org/downloads.jsp http://swinglabs.org/downloads.jsp
  3. GoogleEarth inside Java Swing Java Swing中的GoogleEarth
  4. Is there a Swing component for Google Maps? Google Maps有Swing组件吗?
  5. http://code.google.com/p/gameplan/source/browse/trunk/src/org/crazydays/gameplan/map/swing/JMapFrame.java?spec=svn62&r=62 http://code.google.com/p/gameplan/source/browse/trunk/src/org/crazydays/gameplan/map/swing/JMapFrame.java?spec=svn62&r=62

I am more of a SWT fan, so I would have used a browser control as it allows me to execute javascript on the browser component. 我更喜欢SWT迷,所以我会使用浏览器控件,因为它允许我在浏览器组件上执行javascript。 But again its a design choice. 但同样,它是一种设计选择。

Hope this will help. 希望这会有所帮助。

I am not entirely clear on the scope of your issue, but you may find it helpful to attach MouseListener interfaces to your swing buttons 我对您的问题的范围尚不完全清楚,但是您可能会发现将MouseListener界面附加到您的挥杆按钮会有所帮助

http://download.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html http://download.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html

http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html

Implementing the mouseClicked method to run the required java script. 实现mouseClicked方法以运行所需的Java脚本。

Additionally you could use a MouseAdapter if all you need is the mouseClicked functionality. 另外,如果您只需要mouseClicked功能,则可以使用MouseAdapter。

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

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