读书人

JFileChooser的施用

发布时间: 2012-11-03 10:57:42 作者: rapoo

JFileChooser的使用

下面是JFileChooser使用的部分代码:

?

 @Action    public void selectFileAction() {        JFileChooser chooser = new JFileChooser();        FileNameExtensionFilter filter = new FileNameExtensionFilter(                "JPG & GIF Images", "jpg", "gif");        chooser.addChoosableFileFilter(new FileNameExtensionFilter("支持的音频文件", "mp3", "wav"));        chooser.setFileFilter(filter);        int returnVal = chooser.showDialog(this, "运行");//        int returnVal = chooser.showSaveDialog(this);//        int returnVal = chooser.showOpenDialog(this);        if (returnVal == JFileChooser.APPROVE_OPTION) {            System.out.println("You chose to open this file: "                    + chooser.getSelectedFile().getName());            System.out.println(chooser.getSelectedFile().getAbsolutePath());        } else if (returnVal == JFileChooser.CANCEL_OPTION) {            System.out.println("You chose cancel");        }    }
?

读书人网 >操作系统

热点推荐