Perché non gestisci l'eccezione? Prova quanto meno a fare un
codice:
ex.printStackTrace();
dentro al catch!!
Poi ad occhio direi che stai mescolando Swing con AWT ed è male.
Un esempio un po' più funzionante potrebbe essere:
codice:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
/**
*
* @author Andrea
*/
public class JFileChooserTest extends JFrame {
JTextArea ta;
private class MyActionListener implements ActionListener {
JFileChooserTest fct;
public MyActionListener (JFileChooserTest fct) {
this.fct = fct;
}
public void actionPerformed (ActionEvent ae) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
chooser.showOpenDialog(fct);
try {
File f = new File(chooser.getSelectedFile().getPath());
BufferedReader in = new BufferedReader(new FileReader(f));
String line;
while((line = in.readLine()) != null) {
ta.append("\n" + line);
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
public JFileChooserTest() {
super("Another test");
this.setSize(600,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton open = new JButton("Apri...");
this.getContentPane().add(open, BorderLayout.SOUTH);
ta = new JTextArea();
this.getContentPane().add(new JScrollPane(ta), BorderLayout.CENTER);
open.addActionListener(new MyActionListener(this));
this.setVisible(true);
}
public static void main (String[] args) {
new JFileChooserTest();
}
}
Per brevità ho eliminato la gestione delle azioni del JFileChooser, cosa che invece andrebbe fatta.