import java.awt.BorderLayout;输出:
导入 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
导入 java.io.File;
import javax.swing.JFileChooser;
导入 javax.swing.JFrame;
import javax.swing.JMenu;
导入 javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class JFileChooserTest {
public static void main(String[] args) {
final JFrame window = new JFrame();
window.setSize(200,200);
window.setLocationRelativeTo(null);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu(Ficher”);
JMenuItem Open = new JMenuItem(Open”);
jm.add(打开);
jmb.add(jm);
window.add(jmb,BorderLayout.NORTH);
JFileChooser fc = new JFileChooser();
Open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成的方法 stub
int val_retour = fc.showOpenDialog(window);
if (val_retour == JFileChooser.APPROVE_OPTION) {
文件文件 = fc.getSelectedFile();
//显示文件名
System.out.println(文件名: ”+file.getName()+\n”);
//显示文件的绝对路径
System.out.println(绝对路径:”+file.getAbsolutePath()+\n”);
} else {
System.out.println(打开已取消\n”);
}
}
});
}
}
文件名: decTo Binaire.cpp要检索所选文件,请使用方法 getSelectedFile()。如果返回值为JFileChooser.APPROVE_OPTION,返回值是 class File.
文件名:C:\Users\VAIO\Documents\CC++\decTo Binaire.cpp
final JFileChooser fc = new JFileChooser();Runtime:
fc.setMultiSelectionEnabled(true)
Open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO 自动生成的方法 stub
int val_retour = fc.showOpenDialog(window);
if (val_retour == JFileChooser.APPROVE_OPTION) {
File[] file = fc.getSelectedFiles();
//遍经文件集的循环
for(File f:file){
System.out.println(文件名: ”+f.getName()+\n”);
System.out.println(绝对路径:”+f.getAbsolutePath()+\n”);
}
} else {
System.out.println(打开已取消\n”);
}
}
});
文件名:decTo Binaire.cppReferences:
绝对路径:C:\Users\VAIO\Documents\CC++\decTo Binaire.cpp
文件名:decalage_tableau.cpp
绝对路径:C:\Users\VAIO\Documents\CC++\decalage_tableau.cpp
文件名: determinant_matrice.cpp
绝对路径:C:\Users\VAIO\Documents\CC++\determinant_matrice.cpp
文件名:equation-1-degre.cpp
绝对路径:C:\Users\VAIO\Documents\CC++\equation-1-degre.cpp
Please disable your ad blocker and refresh the window to use this website.