Results 1 to 5 of 5
  1. #1
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default how to execute a code after the endless loops?

    hello guys i ask this because im doing this.
    i create a dos app and it runs on start up application then every time my computer runs i record the current time and date on text file.

    then my big problem is i cant record the current time and date if i turn off my computer
    see my code i hope some one can help me and thanks

    Java Code:
    public class Main {
      public static void main(String[]args){
          // i will record the current time in textfile every time i turn on my computer using filewriter     
          while(true){
              //this is endless loops  
          }
          //then if my computer turn of i will record the current time in textfile
          //the problem is i cant execute my code on exit. 
        // how to execute a code after the endless loops?
      }   
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    cant record the current time and date if i turn off my computer
    Are you asking if there is a way for the OS to tell your code that the computer is being turned off?

  3. #3
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    Are you asking if there is a way for the OS to tell your code that the computer is being turned off?

    my be Yes..
    is their any way to do that?

    if No
    how to execute a code after endless loops.
    (i mean how to execute a code if i turn of my application)?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Perhaps you want to intermittently write the time to a file, and then the last time written should be close to the time that the computer was turned off.

  5. #5
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Default

    what do you mean? how does it help?

    while my application is running the time and date are recorded into text file is this what you are saying? if yes
    how about this one?

    how to invoke a method if the computer is shutting down?
    Last edited by Jhovarie; 07-26-2011 at 02:00 AM.

Similar Threads

  1. Replies: 20
    Last Post: 03-22-2011, 04:02 AM
  2. Unable to execute my code can u plz help me out
    By Gayathri12 in forum New To Java
    Replies: 6
    Last Post: 07-21-2010, 08:28 AM
  3. Execute code from ActionListener
    By Viola in forum New To Java
    Replies: 3
    Last Post: 05-29-2010, 05:10 PM
  4. Compile/Execute code in Java app
    By Doctor Cactus in forum New To Java
    Replies: 5
    Last Post: 12-16-2008, 09:58 AM
  5. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 08:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •