首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

JFileChooser的施用

2012-11-03 
JFileChooser的使用下面是JFileChooser使用的部分代码:? @Actionpublic void selectFileAction() {JFileCh

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");        }    }
?

热点排行