Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hi,
I've to let the choice to user for a file !
So I've tried a simple JFrame with JfileChooser object in a routine call by tjavaflex ...
But I haven't got the time to choice anything
The frame still open a very short time to disappear ...
problem of thread !??
I'm not enought java coder to find the reason why !!
here the code :
public class FileChooser extends JFrame implements ActionListener{
private JButton bouton = null;
private JPanel panel = null;
private String thePath = null;
public FileChooser(){
panel = new JPanel();
bouton = new JButton();
panel.setLayout(new FlowLayout());
bouton.addActionListener(this);
this.setVisible(true);
this.setSize(new Dimension(400,200));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
JFileChooser chooser = new JFileChooser();
File theFile = null;
if(source == bouton){
int returnVal = chooser.showOpenDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION){
theFile = chooser.getSelectedFile();
}
}
thePath = theFile.toURI().toString();
}
public String getPath(){
return thePath;
}
}
Hope it's not too long !
Why frame close just as it open !??
thanks for your help or suggestion