zoukankan      html  css  js  c++  java
  • 在线Google Map在swing中的应用

    引用:http://hi.baidu.com/newjavaee/item/3be4f32060eb8b102a0f1cb4

    一个小东西,C/S程序中调用在线google map。

    不过需要用到一种技术,DJ NativeSwing 一个开源框架,很好用的。

    demo如下:

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package newgpsclientui;
    import chrriis.common.UIUtils;
    import chrriis.dj.nativeswing.swtimpl.NativeInterface;
    import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
    import java.awt.BorderLayout;
    import java.net.URL;
    import javax.swing.*;
    public class TestMap {   
      
      public static JComponent createContent() {   
        JWebBrowser webBrowser = new JWebBrowser();   
        webBrowser.setBarsVisible(false);   
        URL path =WebBrowserFunctionExample.class.getResource("/");
        String script1 ="<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\" type=\"text/javascript\"></script>";
        String script2="<script type=\"text/javascript\" src=\""+path+"google/markerwithlabel.js\"></script>";
        String script3="<script type=\"text/javascript\" src=\""+path+"google/infobubble.js\"></script>";
        String script4="<script type=\"text/javascript\" src=\""+path+"google/google_map.js\"></script> ";
        String jquery = "<script type=\"text/javascript\" src=\""+path+"js/jquery.js\"></script>";
        String script5="<head><style type=\"text/css\">#mapbar{ height:100%;100%;}</style></head>";
        String script6="<script type=\"text/javascript\">$(document).ready(function(){ initMap();});</script>";
        String div ="<body ><div id=\"mapbar\"></div></body>";
        System.out.println(script1+script2+script3+script4+script5+div);
        webBrowser.setHTMLContent(jquery+script1+script2+script3+script4+script5+div+script6); 
        return webBrowser;   
      }   
      
      /* Standard main method to try that test as a standalone application. */  
      public static void main(String[] args) {   
        NativeInterface.open();   
        UIUtils.setPreferredLookAndFeel();   
        SwingUtilities.invokeLater(new Runnable() {   
          public void run() {   
            JFrame frame = new JFrame("DJ Native Swing Test");   
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
            frame.getContentPane().add(createContent(), BorderLayout.CENTER);   
            frame.setSize(800, 600);   
            frame.setLocationByPlatform(true);   
            frame.setVisible(true);   
          }   
        });   
        NativeInterface.runEventPump();   
      }   
      
    } 

     运行效果如图:swing中引入Google Map

  • 相关阅读:
    数理统计与Matlab: 第4章 回归分析
    汽车各部位名称详解【图】
    线性代数:第四章 矩 阵1
    曲线救国的就业路线是否合理?
    TortoiseSVN 编辑日志信息报错
    Ironpython及其他托管语言中值类型最好使用构造函数赋值,否则无法赋值的问题
    线性代数:第五章 二次型
    Matlab基础
    技术基层管理者交流QQ群243460070
    MATLAB软件基础
  • 原文地址:https://www.cnblogs.com/yony/p/2944267.html
Copyright © 2011-2022 走看看