I am creating a GUI using methods and classes, and am trying to create a button where the user can select it and then choose a file. The file will then read in what is stored in the file into a textarea/textfield/JLabel. Can anyone help me with my code, I'm not sure how to code it so I can select the button to choose a file and it then reads the text into the GUI.
public void addLoadFile(){
btnLoadFile = new JButton("Load file of Books");
btnLoadFile.setBounds(415, 30, 150, 20);
btnLoadFile.addActionListener(this);
panelLoadFile.add(btnLoadFile);
textArea = new JTextArea();
}
class this implements ActionListener {
@Override
JFileChooser fileChooser = new JFileChooser();
int ret = fileChooser.showOpenDialog(this);
if(ret== JFileChooser.APPROVE_OPTION)
{
File f= fileChooser.getSelectedFile();
try
{
FileReader r=new FileReader(f);
area.read(4,"");
}
catch (Exception ee)
}
System.out.prinkln("");
}