解决方案 »

  1.   

        public void doSelectQuery() {        // 定义记录集
            Recordset recordset = null;        // 获取图层集合
            Layers layers = mapControl.getMap().getLayers();        // 获取选择集
            Selection selection = null;
            for (int i = 0; i < layers.getCount(); i++) {
                if (layers.get(i).getSelection() != null 
                 && layers.get(i).getSelection().getCount() != 0) {
                    selection = layers.get(i).getSelection();
                }
            }        // 判断选择集是否为空
            if ((selection == null) || (selection.getCount() == 0)) {
                JOptionPane.showMessageDialog(this, "请选择要查询属性的空间对象");
                return;
            }        // 将选择集转换为记录集
            recordset = selection.toRecordset();        // 获取记录集中记录的字段数
            int fieldCount = recordset.getFieldCount();        // 获取记录集中的记录数
            int recordCount = recordset.getRecordCount();        // 定义Table
            Object[][] tableValues = new Object[recordCount][fieldCount];
            Object[] tableColumns = new Object[fieldCount];        // 将字段值添加到jTable控件相应的位置
            for (int i = 0; i < fieldCount; i++) {
                tableColumns[i] = recordset.getFieldInfos().get(i).getName();
            }        for (int i = 0; i < recordCount; i++) {
                for (int j = 0; j < fieldCount; j++) {
                    tableValues[i][j] = recordset.getFieldValue(j);
                }
                recordset.moveNext();
            }
            
            recordset.dispose();
            recordset = null;        // 将查询到信息加到 Table 中显示
            DefaultTableModel tableModel = new DefaultTableModel(tableValues,
                    tableColumns);
            this.table.setModel(tableModel);
        }    public void doSQLQuery() {        // 判断JTextField 的输入内容是否为空
         String filter =txtFilter.getText().trim(); 
            if (filter.isEmpty()) {
                JOptionPane.showMessageDialog(this, "查询信息不能为空");
                return;
            }        // 定义查询条件信息
            QueryParameter queryParameter = new QueryParameter();
            queryParameter.setAttributeFilter(filter);
            queryParameter.setCursorType(CursorType.STATIC);        // 定义图层个数,判断当前地图窗口中是否有打开的图层
            int queryCount = mapControl.getMap().getLayers().getCount();
            if (queryCount == 0) {
                JOptionPane.showMessageDialog(this, "请先打开一个矢量数据集!");
                return;
            }        // 遍历每一个图层,实现多图层查询
            int flag = 0;
            for (int i = 0; i < queryCount; i++) {
                // 得到矢量和栅格数据集并强制转换为矢量数据集类型
    Dataset dataset = 
    mapControl.getMap().getLayers().get(i).getDataset();
    if (dataset.getType() == DatasetType.IMAGE) {continue;}
                DatasetVector datasetvector=(DatasetVector)dataset;
                if (datasetvector == null) {
                    continue;
                }            // 打开矢量数据集,才可进行查询
                datasetvector.open();            // 通过查询条件对矢量数据集进行查询,从数据集中查询出属性数据
                Recordset recordset = datasetvector.query(queryParameter);            // 查询结果不为空则给 flag 赋值为1
                if (recordset.getRecordCount() > 0) {
                    flag = 1;
                }            // 把查询得到的数据加入到选择集中(使其高亮显示)
                Selection selection = mapControl.getMap()
                 .getLayers().get(i).getSelection();
                selection.fromRecordset(recordset);            // 注意:此处需要调用 dispose 方法,否则对 SDB 数据会崩溃。
                recordset.dispose();
                recordset = null;
            }
            // 判断记录集是否为空
            if (flag == 0) {
                JOptionPane.showMessageDialog(
                 this, "查询得到的记录集为空或者没有满足查询条件的记录!");
            }
            // 刷新地图窗口显示
            mapControl.getMap().refresh();        // 当可创建对象使用完毕后,使用 dispose 方法来释放所占用的内部资源。
            queryParameter.dispose();
        }    // 设置地图及属性表的大小随窗体变化而改变
        public void this_componentResized(ComponentEvent e) {
            mapControl.setSize(this.getWidth() - 25,
                                7 * (int)this.getHeight() / 12);        jScrollPane1.setLocation(10, 7 * (int)this.getHeight() / 12 + 46);
            jScrollPane1.setSize(this.getWidth() - 25,
                                 (int) 5 * (int)this.getHeight() / 12 - 80);
            table.setLocation(10,
                              7 * (int)this.getHeight() / 12 + 46);
            table.setSize(this.getWidth() - 25,
                          (int)this.getHeight() / 2 - 130);
        }    public void this_windowClosing(WindowEvent e) {
            if (mapControl != null) {
                mapControl.dispose();
                mapControl = null;
            }
            if (workspace != null) {
                workspace.dispose();
                workspace = null;
            }
        }
    }
    class Frame1_this_componentAdapter extends ComponentAdapter {
        private Frame1 adaptee;
        Frame1_this_componentAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }    public void componentResized(ComponentEvent e) {
            adaptee.this_componentResized(e);
        }
    }class Frame1_this_windowAdapter extends WindowAdapter {
        private Frame1 adaptee;
        Frame1_this_windowAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        }    public void windowClosing(WindowEvent e) {
            adaptee.this_windowClosing(e);
        }}不知道如何下手,小白求指导,希望能提供源码,封装及思考步骤,分全部送上,在此谢过了...