JFileChooser.java
public int showDialog(Component parent, String approveButtonText)

解决方案 »

  1.   

    import java.awt.event.*;
    import javax.swing.*;public class Demo extends JFrame implements ActionListener {
        private JMenuBar _menuBar = new JMenuBar();
        private JMenu _file = new JMenu("File");
        private JMenuItem _open = new JMenuItem("Open");
        //生成一个文件选择器,"c:\\"为直接打开C盘根目录
        private JFileChooser _chooser = new JFileChooser("c:\\");    public Demo(String s) {
          super(s);
          _open.addActionListener(this);
          _file.add(_open);
          _menuBar.add(_file);
          this.setJMenuBar(_menuBar);
          this.setBounds(200,200,200,200);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.show();
        }    public void actionPerformed(ActionEvent e) {
            if(e.getSource() == _open) {
                //显示文件打开对话框,保存对话框为showSaveDialog
                _chooser.showOpenDialog(this);
            }
        }    public static void main(String[] args) {
            new Demo("今天我有空");
        }
    }