JFileChooser!

Ola!!
eu fiz esse programinha , mas eu quero q quando eu selecionar o arquivo ele abra independente se ser txt ou imagem, se algum pode me ajudar eu agradeceria, pois eu naum consigo fazer .

o codigo é esse:

[code]import java.awt.;
import java.awt.event.
;
import javax.swing.*;

public class TesteJanela extends JFrame {

private JFileChooser fileChooser = new JFileChooser();
private JButton botaoOk = new JButton("Escolher");
private JLabel lNomeArquivo = new JLabel("");
private JFrame eu = this;

public TesteJanela() {
	super ("Visulation 1.0");
	setDefaultCloseOperation (EXIT_ON_CLOSE);
	
	Container c = getContentPane();
	c.setLayout(new GridLayout(3,1));
	String msg = "Clique no Botão para escolher o arquivo";
	JLabel lDigiteNomeArquivo = new JLabel(msg);
	c.add(lDigiteNomeArquivo);
	c.add(botaoOk);
	c.add(lNomeArquivo);
	
	botaoOk.addActionListener(new AbrirArquivoHandler());
	setSize(250,100);
	show();
}

class AbrirArquivoHandler implements ActionListener {
	public void actionPerformed (ActionEvent e) {
		int opcao = fileChooser.showOpenDialog(eu);
		
		if (opcao == JFileChooser.APPROVE_OPTION) {
			String arquivoSelecionado=fileChooser.getSelectedFile().getName();
			lNomeArquivo.setText(arquivoSelecionado);
		}
		
		else if (opcao == JFileChooser.CANCEL_OPTION) {
			lNomeArquivo.setText("Operação cancelada");
		}
	}
}
public static void main (String args[]) {
	TesteJanela t = new TesteJanela();
}

}[/code]

atenciosamente

Andre Muniz

boa! essa ai tb quero saber…

Ainda acrescento, tem como eu criar um visualizador PDF dentro do JFrame, como se fosse uma página Web?

mas como? voce quer abrir um txt dentro de um label?
num da nao cara, tipo o JLabel nao suporta linefeed, entao o melhor seria abrir o texto em uma JTextArea mesmo…

bem, respondendo a sua pergunta, basta usar um filtro no filechooser pra abrir so txt, jpg, gif ou png, ai voce da um endsWith() pra saber se eh txt(abre na textarea) ou imagem (abre no label).
acho q da pra fazer assim.

flw