Hello, I think you need to make use of the code below for getting knowledge about the Java JFilechoser. So, make use of it.
Code:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing .*;
import java.awt .*;
import java.awt .*;
import java.io. *;
Public class FileChooser extends JFrame implements ActionListener{
private JButton b1 = new JButton("Select a file");
private JTextField t1 = new JTextField("No file loaded!");
private JPanel panel = new JPanel();
Public FileChooser()
{
this.setTitle("JFileChooser");
this.setSize(500, 100);
this.setLocationRelativeTo(null);
t1.setEditable(false);
b1.addActionListener(this);
panel.setBackground(Color.CYAN);
JPanel pane = new JPanel();
pane.add(t1);
pane.add(b1);
panel.add(Pane);
this.setContentPane(panel);
this.setVisible(true);
}
Public void actionPerformed(ActionEvent evt)
{
JFileChooser chooser = new JFileChooser();
chooser.showFileChooserDialog(null);
if (chooser.showFileChooserDialog(null) == JFileChooser.APPROVE_OPTION)
{
t1.setText(chooser.getSelectedFile().getAbsolutePath());
}
}
}
and here is the code that call this class from my applet
if (evt.getActionCommand().equals("File"))
{
FileChooser = new FileChooser();
FileChooser.show();
}
Bookmarks