///以下是关键部分代码,运行良好,就是不会调"打开通用对话框"
class MainPanel extends JPanel
{
public MainPanel()
{
JLabel lblIn = new JLabel("源文件:");
lblIn.setBounds(30, 30, 50, 20);
JTextArea txtInFile = new JTextArea();
txtInFile.setBounds(80,30,100,20);
JButton btnSelect = new JButton("选择文件");
btnSelect.setBounds(190, 30, 80, 20);
JFileChooser open = new JFileChooser();
btnSelect.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((JButton)e.getSource()).setLabel("已选"); //这里我想弹出一个打开文件的通用对话框应该怎么调用?
System.out.println("打开文件"); //调用这方法JFileChooser.showOpenDialog(this)不对..
}
}
);
JLabel lblOut = new JLabel("复制到:");
lblOut.setBounds(30, 60, 50, 20);
JTextArea txtOutFile = new JTextArea();
txtOutFile.setBounds(80,60,100,20);
JButton btnCopy = new JButton("开始复制");
btnCopy.setBounds(60, 90, 90, 20);
add(lblIn);
add(txtInFile);
add(btnSelect);
add(lblOut);
add(txtOutFile);
add(btnCopy);
}