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