The Artima Developer Community
Sponsored Link

Java Answers Forum
Halting the current working system from a java program

3 replies on 1 page. Most recent reply: Feb 24, 2004 8:54 AM by Augusto

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Jacob

Posts: 4
Nickname: kimi
Registered: Jan, 2004

Halting the current working system from a java program Posted: Feb 24, 2004 1:01 AM
Reply to this message Reply
Advertisement
I need to turn off my system by pressing a "Turn Off Computer" button in my java application. Can anyone help me in getting the code for that....??


Viswanatha Basavalingappa

Posts: 84
Nickname: viswagb
Registered: Nov, 2003

Re: Halting the current working system from a java program Posted: Feb 24, 2004 2:07 AM
Reply to this message Reply
Yes, you can do it by calling System.exit(0) on the event clcik of button.

Here is the sample code for the samer
    protected JButton b1;
 
    public ButtonTurnOff() 
    {
    
        b1 = new JButton("Turn Off Computer");
        b1.setActionCommand("Turn Off Computer");
		b1.addActionListener(this);
        add(b1);
    }
 
    public void actionPerformed(ActionEvent e) 
    {
        if ("Turn Off Computer".equals(e.getActionCommand())) 
        {
           System.exit(0); //  is effectively equivalent to the call Runtime.getRuntime().exit(0)
        }
       
    }


hope this helps you...

Viswa
--------

Jacob

Posts: 4
Nickname: kimi
Registered: Jan, 2004

Re: Halting the current working system from a java program Posted: Feb 24, 2004 4:05 AM
Reply to this message Reply
Viswa...
I tried with your code ..but the problem is that my java application closes but my system is not turned off. I want my Computer to be turned OFF from the click of " Turn Off Computer" Button in my java application...

Augusto

Posts: 1
Nickname: arodriguez
Registered: Feb, 2004

Re: Halting the current working system from a java program Posted: Feb 24, 2004 8:54 AM
Reply to this message Reply
Hi Jacob!

you need to interact with the windows api. To do this you must use JNI (Java Native Interface) and using c or c++ you have to invoke the "ExitWindowsEx" function wich resides in the user32.dll library.

Or the easy way is to make a program in another language like C++ or C# (there are a lot of examples to make a shutdown program in c#) and call the shutdown function there. And then executing that program inside java using the java.lang.Runtime.exec() method.

cheers.
Augusto.

Flat View: This topic has 3 replies on 1 page
Topic: J2EE Architecture - Scalability Previous Topic   Next Topic Topic: Copying icon and string from one JList to another JList

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use