Hello friends,
I am making an application in which I need to shutdown unix system through
gui interface..I am trying to do this work through java.
I tried this code on my fedora for shutting system down .Its not working...I
did this work in windows ..its working there but not on fedora.............
import java.io.IOException;
public class Main {
public static void main(String[] args)throws IOException {
Runtime runtime=Runtime.getRuntime();
Process proc=runtime.exec("shutdown now -h 0");
System.exit(0);
}
}
*This is my full code with GUI but the basic problem is in above code....The
following code is to just show my application(i.e on pressing button system
shuts down)*
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.io.*;
public class Main extends JFrame {
JLabel jl;
public Main()
{
JFrame f=new JFrame();
f.setSize(200,200);
JPanel p=new JPanel();
f.getContentPane().add(p);
JButton jb=new JButton("b1");
p.add(jb);
Handler h=new Handler();
jb.addActionListener(h);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class Handler implements ActionListener
{
public void actionPerformed(ActionEvent e) {
shut sh=new shut();
sh.shutdown();
}
}
class shut
{
public void shutdown(){
try{
Runtime runtime=Runtime.getRuntime();
Process proc=runtime.exec("shutdown now -h -t 0 ");
System.exit(0);}
catch(IOException ae)
{ System.out.println("error occured");}
}
}
public static void main(String[] args) {
Main main = new Main();
}
}
--
Mailing list guidelines and other related articles: http://lug-iitd.org/Footer