• 0

[Java] Excuting method on closing of JFrame


Question

I have a simple Swing application that is contained in a JFrame. To quit/exit the application, I simply used the:

myJFrame.setDefaultCloseOperation(EXIT_ON_CLOSE)

so it quits when you click the X in the corner, but I want to call to delete a lock file when I quit the application. How can I do this?

Or is there an easier way to setup File Locking with Java 1.4.2? I know there is something using FileChannel and FileLock but it seems complicated.

I just want my program to not open a file if another person has the file already open. So I thought I would just create a dummy lock file when I open it, and test for it when you try and open. But it needs to be deleted when I quit.

Any help would be greatly appreciated.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0
I have a simple Swing application that is contained in a JFrame. To quit/exit the application, I simply used the:

myJFrame.setDefaultCloseOperation(EXIT_ON_CLOSE)

so it quits when you click the X in the corner, but I want to call to delete a lock file when I quit the application. How can I do this?

Or is there an easier way to setup File Locking with Java 1.4.2? I know there is something using FileChannel and FileLock but it seems complicated.

I just want my program to not open a file if another person has the file already open. So I thought I would just create a dummy lock file when I open it, and test for it when you try and open. But it needs to be deleted when I quit.

Any help would be greatly appreciated.

584816261[/snapback]

Delete that method call. Use a WindowListener and then put the method to delete the lock file in the windowClosed method...

If you need more help just say let me know.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.