I'm trying to make a button in NetBeans IDE that opens a File Chooser window and sends the file after the user selects. The send_file method belongs to the Connection_tcp class and is a public boolean.
The IDE doesn't allow this code because it claims I can't use a non static method in a static context. This refers to the Connection_tcp.send_file(selectedFile); line. How do I correct this error?
I don't know if this is a simple question because I'm still starting to learn and this is a school assignment.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser j = new JFileChooser();
j.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = j.showSaveDialog(this);
if(result == JFileChooser.APPROVE_OPTION){
File selectedFile = j.getSelectedFile();
Connection_tcp.send_file(selectedFile);
}
}