aspose file tools
The moose likes Swing / AWT / SWT and the fly likes Not able to delete file using JButton in a frame Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "Not able to delete file using JButton in a frame " Watch "Not able to delete file using JButton in a frame " New topic
Author

Not able to delete file using JButton in a frame

ahmedali mohd
Greenhorn

Joined: Apr 14, 2010
Posts: 15

I want to delete a file when i click the JButton or unchecked the JCheckBox option.. I m added actions to these components a well. Doing action but not deleting the file Why i don't know.
See the code ... I tried on deleteonExit() as well. But it is not doing if im doing through main() method that normal class, i can delete it ...

addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
update_user();
// delete_operation();
//System.exit(0);
}

public void windowClosed(WindowEvent e) {

File f1=new File("ahmedali.dat");
System.out.println("You are in Foperations"+f1);
System.out.println(" Inside delete");
if(f1.exists()) { System.out.println("File is deleted:");f1.delete(); }
f1=null;
}

}

);
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8431

You should be using an ActionListener to perform the delete operation when the button is clicked.
Recommended reading http://java.sun.com/docs/books/tutorial/uiswing/components/button.html


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
ahmedali mohd
Greenhorn

Joined: Apr 14, 2010
Posts: 15

I ve performed action listeners to button already and i 've used mouselisteners also to do the operations, but it is not working... please let me know .
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8431

Well if you have noticed, you have posted some WindowAdapter code which tries to delete the files.
If you need help, you need to help us help you by posting SSCCE code which we can try out and identify the problem.

PS. Please do take out time to read what SSCCE really means before posting code.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Not able to delete file using JButton in a frame
 
Similar Threads
File I/O
problem in rediredtin GUI to IO Streams
File renameTo()
error while creating a new file
AWT Event