swing中调用文件选择对话框

类别:Java 点击:0 评论:0 推荐:
import javax.swing.*;
.
.
.
public class jCutter extends JFrame {
 private JTextField textField;
 private JButton button;
 private JFileChooser fDialog;
 private JFrame frame;
.
.
.
  button = new JButton();
  button.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e){
    String msg;
    fDialog=new JFileChooser(); //文件选择器
    int result=fDialog.showOpenDialog(frame);
    if(result==JFileChooser.APPROVE_OPTION){
     String fname=fDialog.getName(fDialog.getSelectedFile());
     frame.setTitle(fname);
     msg="File Open Approved";
    }else
     msg="File Open Cancelled";
    JOptionPane.showMessageDialog(frame,msg); //提示框
   }
  });

本文地址:http://com.8s8s.com/it/it15723.htm