当前位置: 代码迷 >> J2SE >> 加急扭结,求代码大神将以下代码封装成公共函数的形式,然后供外界直接调用
  详细解决方案

加急扭结,求代码大神将以下代码封装成公共函数的形式,然后供外界直接调用

热度:13   发布时间:2016-04-23 20:05:08.0
加急,纠结,求代码大神将以下代码封装成公共函数的形式,然后供外界直接调用
package gettingstarted;

import com.supermap.data.*;
import com.supermap.mapping.*;
import com.supermap.ui.*;
import com.supermap.ui.Action;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.table.*;

public class Frame1 extends JFrame {

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel(
                 UIManager.getSystemLookAndFeelClassName());
            } catch (Exception exception) {
                exception.printStackTrace();
            }

            Frame1 frame = new Frame1(); //实例化一个窗体
            frame.setVisible(true); //显示窗体
        }
    });
}

    
    Workspace workspace = new Workspace(); //定义工作空间类型
    MapControl mapControl = new MapControl(); //

    //定义界面
    JPanel panelMain;
    JButton jButtonOpen = new JButton();
    JButton jButtonPan = new JButton();
    JButton jButtonZoomIn = new JButton();
    JButton jButtonZoomOut = new JButton();
    JButton jButtonZoomFree = new JButton();
    JButton jButtonViewEntire = new JButton();
    JButton jButtonSelect = new JButton();
    JButton jButtonSelectQuery = new JButton();
    JScrollPane jScrollPane1 = new JScrollPane();
    JTable table = new JTable();
    JLabel lblTag = new JLabel();
    JButton jButtonSQLQuery = new JButton();
    JTextField txtFilter = new JTextField();
    JToolBar jToolBar1 = new JToolBar();
    
    
    // 为按钮添加图片
    ImageIcon selectionIcon = new ImageIcon("Resources/action_select.png");
    ImageIcon openIcon = new ImageIcon("Resources/workspace_open.png");
    ImageIcon panIcon = new ImageIcon("Resources/action_pan.png");
    ImageIcon zoominIcon = new ImageIcon("Resources/action_zoomin.png");
    ImageIcon zoomoutIcon = new ImageIcon("Resources/action_zoomout.png");
    ImageIcon zoomfreeIcon = new ImageIcon("Resources/action_zoomfree.png");
    ImageIcon viewentireIcon = new ImageIcon("Resources/action_viewentire.png");
    ImageIcon selectqueryIcon = new ImageIcon("Resources/action_selectquery.png");
    ImageIcon sqlqueryIcon = new ImageIcon("Resources/action_sqlquery.png");

    
    public Frame1() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            initialize();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

   //初始化方法
   private void initialize() throws Exception {
   
        panelMain = (JPanel) getContentPane();
        this.setSize(new Dimension(710, 350));
        this.setTitle("SuperMap Objects Java");
        this.addWindowListener(new Frame1_this_windowAdapter(this));
        this.addComponentListener(new Frame1_this_componentAdapter(this));
        mapControl.setLayout(null);
        panelMain.setLayout(null);
        mapControl.setBounds(new Rectangle(9, 44, 650, 181));
        
        jButtonOpen.setToolTipText("打开地图");
        jButtonOpen.setIcon(openIcon);
        jButtonOpen.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 打开工作空间及地图
        openMap();
}
        });
        
        jButtonPan.setToolTipText("漫游");
        jButtonPan.setIcon(panIcon);
        jButtonPan.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 地图漫游
        mapControl.setAction(Action.PAN);
}
        });
        
        jButtonZoomIn.setToolTipText("放大");
        jButtonZoomIn.setIcon(zoominIcon);
        jButtonZoomIn.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 地图放大
        mapControl.setAction(Action.ZOOMIN);
}
        });
        
        jButtonZoomOut.setToolTipText("缩小");
        jButtonZoomOut.setIcon(zoomoutIcon);
        jButtonZoomOut.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 地图缩小
        mapControl.setAction(Action.ZOOMOUT);
}
        });
        
        jButtonZoomFree.setToolTipText("自由缩放");
        jButtonZoomFree.setIcon(zoomfreeIcon);
        jButtonZoomFree.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 地图自由缩放
        mapControl.setAction(Action.ZOOMFREE);
}
        });
        
        jButtonViewEntire.setToolTipText("全幅显示");
        jButtonViewEntire.setIcon(viewentireIcon);
        jButtonViewEntire.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 地图全幅显示
        mapControl.getMap().viewEntire();
        mapControl.getMap().refresh();
}
        });
        
        jButtonSelect.setToolTipText("选择");
        jButtonSelect.setIcon(selectionIcon);
        jButtonSelect.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 选择对象(此处支持选择多个对象)
        mapControl.setAction(Action.SELECT2);
}
        });
        
        jButtonSelectQuery.setToolTipText("图查属性");
        jButtonSelectQuery.setIcon(selectqueryIcon);
        jButtonSelectQuery.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 执行图查属性
doSelectQuery();
}
        });
        
        jScrollPane1.setBounds(new Rectangle(8, 226, 650, 82));

        lblTag.setToolTipText("");
        lblTag.setText("查询条件:");
        jButtonSQLQuery.setToolTipText("属性查图");
        jButtonSQLQuery.setIcon(sqlqueryIcon);
        jButtonSQLQuery.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// 执行属性查图
doSQLQuery();
}
        });
        
        jToolBar1.setBounds(new Rectangle(3, 10, 700, 27));
        txtFilter.setToolTipText("");
        txtFilter.setColumns(10);
        panelMain.add(jToolBar1);
        jToolBar1.add(jButtonOpen);
        jToolBar1.add(jButtonPan);
        jToolBar1.add(jButtonZoomIn);
        jToolBar1.add(jButtonZoomOut);
        jToolBar1.add(jButtonZoomFree);
        jToolBar1.add(jButtonViewEntire);
        jToolBar1.add(jButtonSelect);
        jToolBar1.add(jButtonSelectQuery);
        jToolBar1.add(lblTag);
        jToolBar1.add(txtFilter);
        jToolBar1.add(jButtonSQLQuery);
        panelMain.add(mapControl, null);
        panelMain.add(jScrollPane1);
        jScrollPane1.getViewport().add(table);
    }

    public void openMap() {
    
        // 设置公用打开对话框
        FileDialog openFileDialog = new FileDialog(this, "打开工作空间", FileDialog.LOAD);

        openFileDialog.setVisible(true);

        // 定义并获得一个工作空间连接信息的实例
        WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo();

        // 定义连接工作空间的类型为SMWU
        workspaceConnectionInfo.setType(WorkspaceType.SMWU);

        // 设置连接工作空间文件的路径名
        String filename = openFileDialog.getFile();
        String filedir = openFileDialog.getDirectory();
        String fileworkspace = filedir + filename;
        workspaceConnectionInfo.setServer(fileworkspace);

        // 判断是否成功打开工作空间文件
        if ( !workspace.open(workspaceConnectionInfo) ) {
         JOptionPane.showMessageDialog(this, "打开工作空间失败!");
            return;
        }

        // 建立MapControl与Workspace的连接
        mapControl.getMap().setWorkspace(workspace);

        // 判断工作空间中是否有地图,如果有的话获取工作空间中的地图集
        if (workspace.getMaps().getCount() <= 0) {
            JOptionPane.showMessageDialog(this, "工作空间中没有地图");
            return;
        } 
        
        // 通过名称打开工作空间中的地图
        mapControl.getMap().open("世界地图_Day");

        mapControl.getMap().refresh();

        //打开地图后,将打开地图按钮设为不可用
        jButtonOpen.setEnabled(false);
    }


------解决思路----------------------
引用:
Quote: 引用:

做成一个webservice就可以了


能具体点嘛,不会啊


已发送指楼主邮箱,请查收。
  相关解决方案