免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1105 | 回复: 0
打印 上一主题 下一主题

XP的关机程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-07 22:40 |只看该作者 |倒序浏览
作者:rqfreedom
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.IOException;
public class chongqi implements ActionListener{
static JFrame frm=new JFrame("关机程序");
static JButton shutdown=new JButton("关机");
static JButton rest=new JButton("重启");
static JButton logout=new JButton("注销");
public chongqi(){
frm.getContentPane().setLayout(new GridLayout(1,3));
frm.getContentPane().add(shutdown);
frm.getContentPane().add(rest);
frm.getContentPane().add(logout);
shutdown.addActionListener(this);
   rest.addActionListener(this);
   logout.addActionListener(this);
   frm.pack();
   frm.show();
}
public static void exec(String cmd) {
       try {
           Runtime.getRuntime().exec(cmd);
       }
       catch (IOException e) {
           System.out.println("执行失败");        
       }
   }
   
public static void shutdown() {
       exec("shutdown -S ");
   }
   public static void restart() {
       exec("shutdown -R ");
   }
   public static void logout() {
       exec("shutdown -L ");
   }
   
   public static void main(String args[]){
   
   new chongqi();
   
   }
   
   public void actionPerformed(ActionEvent e){
   if(e.getActionCommand().equals("关机"))
       shutdown();
   else   if(e.getActionCommand().equals("重启"))
       restart();
   else   if(e.getActionCommand().equals("注销"))
           logout();
   }
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/11570/showart_82316.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP