我想在我界面上显示的图片(地图,jpg格式的)上做这样一件事情,当我加载一些数据(坐标)时,能在图上显示出点的位置.其中数据是放在文件中的,我用JFileChooser来实现加载,请教各位师兄我该怎样做啊?
不胜感激。
(似乎是事件的事件的事件的事件,好乱的逻辑,哪位师兄传点源码学习下吧)

解决方案 »

  1.   


        // 返回图片信息
        private static ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = SysAboutDialog.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            }
            JOptionPane.showMessageDialog(sys_jmu, "找不到 :" + path
                                          + "图片路径!请核实您的配置信息。", "错误",
                                          JOptionPane.ERROR_MESSAGE, null);
            return null;
        }
    //不知道有没有用,是以前敲的.这是image加载图片用的.下面的是过滤器.
        /**
         * 文件选择器
         *
         * @param e
         *            标准事件
         */
        public void pro_path_btn_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new JFileChooser();
    File file = null;
            //楼主要看这里的,这是过滤器.写你需要的类型就可以了.至于坐标的话.你看看JDK应该无碍.
    FileNameExtensionFilter filter = new FileNameExtensionFilter(
    "*.jpg & *.gif", "jpg", "gif");
    chooser.setFileFilter(filter);
    int returnVal = chooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
    }
    this.pro_path_jtfel.setText(file.toString());
        }
    }
     //这个是展开树的
    /**
         *  该方法用来展开树
         * @param tree JTree 需要展开的树
         * @param parent TreePath 树的路径
         * @param expand boolean 是否展开
         */
        private void expandAll(JTree tree, TreePath parent, boolean expand) {
            //   Traverse   children
            TreeNode node = (TreeNode) parent.getLastPathComponent();
            if (node.getChildCount() >= 0) {
                for (Enumeration e = node.children(); e.hasMoreElements(); ) {
                    TreeNode n = (TreeNode) e.nextElement();
                    TreePath path = parent.pathByAddingChild(n);
                    expandAll(tree, path, expand);
                }
            }        //   Expansion   or   collapse   must   be   done   bottom-up
            if (expand) {
                tree.expandPath(parent);
            } else {
                tree.collapsePath(parent);
            }
        }