I am using Ubuntu 9.04. I want to shutdown my PC using Java, when some Event is called. Please suggest what could be done.

Well I got it done by this code

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * @author gunjan
public class ShutDown {
    public static void main(String[] args)
        try {
            Runtime.getRuntime().exec("shutdown -h 0");
        } catch (IOException ex) {
            Logger.getLogger(ShutDown.class.getName()).log(Level.SEVERE, null, ex);


But the problem is that I need to run this code as root or superuser. Is there a way to login as root using Java and then run this code