• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to delete file using JButton in a frame

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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;
}

}

);
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ahmedali mohd
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic