Greedy的工作室

          posts - 23,comments - 7,trackbacks - 0
          import java.io.IOException;
          import java.awt.event.*;
          import javax.swing.*;
          public class ShutDown extends JFrame implements ActionListener{
              JButton restart,shutdown,logout;
              Box box;
              public ShutDown(String s) {
                  super(s);
                  restart=new JButton("重起");
                  shutdown=new JButton("關機");
                  logout=new JButton("注銷");
                  box=Box.createHorizontalBox();
                  restart.addActionListener(this);
                  shutdown.addActionListener(this);
                  logout.addActionListener(this);
                  box.add(restart);
                  box.add(shutdown);
                  box.add(logout);
                  add(box);
                  addWindowListener(new WindowAdapter(){
                      public void windowClosing(WindowEvent e)
                              {                      
                                System.exit(0);
                               }
                  });
              }  
              public void exec(String choice) {
                  try {
                      Runtime.getRuntime().exec("cmd /c start call shutdown -"+choice+" -t 0");
                  }
                  catch (IOException e) {
                      System.out.println("執行失敗");      
                  }
              }

              public void shutdown() {
                  exec("S");
              }

              public void restart() {
                  exec("R");
              }

              public void logout() {
                  exec("L");
              }
            public void actionPerformed(ActionEvent e)
              {
                if(e.getSource()==shutdown)
                  {
                     shutdown();
                  }
                  else if(e.getSource()==restart)
                  {
                     restart();
                  }
                  else if(e.getSource()==logout)
                  {
                     logout();
                  }
              }
              public static void main(String[] str) {
                 ShutDown ctr=new ShutDown("關機控制");
                 ctr.setBounds(300,0,200,65);
                 ctr.setVisible(true);
              }
          }
          posted on 2008-06-27 08:52 greedy 閱讀(208) 評論(0)  編輯  收藏 所屬分類: Java技術
          主站蜘蛛池模板: 沙坪坝区| 乐都县| 买车| 新宁县| 焉耆| 竹溪县| 介休市| 岢岚县| 富裕县| 泸溪县| 丘北县| 都安| 福清市| 金阳县| 弥勒县| 加查县| 甘孜| 昌吉市| 壶关县| 黑山县| 乌鲁木齐县| 新宁县| 邹城市| 义乌市| 内黄县| 大石桥市| 平凉市| 保靖县| 稷山县| 乐至县| 泰安市| 清原| 厦门市| 双辽市| 芒康县| 历史| 扶余县| 福州市| 连城县| 宜春市| 兴仁县|