日期:2014-05-20 浏览次数:20897 次
jButton2.setText("Load");
        jButton2.addActionListener(new ActionListener() {
            JFileChooser chooser = new JFileChooser();
            public void actionPerformed(ActionEvent evt) {
                    int result = chooser.showOpenDialog(null);
                    if(result == JFileChooser.APPROVE_OPTION){
                        String pathname = chooser.getSelectedFile().getParentFile().getName();                        System.out.println("File Directory: "+pathname);
                    }
            }
        });
------解决方案--------------------
楼上说得有道,JFileChooser chooser 做成全局变量吧