import java.awt.Dimension;
import java.awt.Image;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
/*
* ShutDownPc.java
*
* Created on __DATE__, __TIME__
*/
/**
*
* @author __USER__
*/
public class ShutDownPc extends javax.swing.JFrame {
private static final long serialVersionUID = 1L;
/** Creates new form ShutDownPc
* @throws Exception
*/
public ShutDownPc() throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
initComponents();
Image image=this.getToolkit().getImage("images\\icon.png");
this.setIconImage(image);
Dimension screen = this.getToolkit().getScreenSize();
this.setBounds((screen.width - 300) / 2, (screen.height - 200) / 2,
300, 200);
Thread thread1 = new Thread(new Runnable() {
public void run() {
Calendar now = null;
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy年MM月dd日HH时mm分ss秒");
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
now = Calendar.getInstance();
String currentTime = sdf.format(now.getTime());
currentTime_lab.setText("当前时间: " + currentTime);
}
}
});
thread1.start();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
currentTime_lab = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
timeToShutDownPc_txt = new javax.swing.JTextField();
timeType_combox = new javax.swing.JComboBox();
setTime_btn = new javax.swing.JButton();
cancelToSetTime_btn = new javax.swing.JButton();
timeToShutDown_lab = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
operationToChoose_combo = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("\u5b9a\u65f6\u5173\u673a");
setResizable(false);
currentTime_lab.setText("\u5f53\u524d\u65f6\u95f4:");
jLabel1.setText("\u8bbe\u7f6e\u65f6\u95f4");
timeType_combox.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "秒", "分", "时" }));
setTime_btn.setText("\u786e\u5b9a\u8bbe\u7f6e");
setTime_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
setTime_btnActionPerformed(evt);
}
});
cancelToSetTime_btn.setText("\u53d6\u6d88\u8bbe\u7f6e");
cancelToSetTime_btn
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelToSetTime_btnActionPerformed(evt);
}
});
timeToShutDown_lab.setText("\u5173\u673a\u65f6\u95f4:");
jLabel2.setText("\u9009\u62e9\u64cd\u4f5c");
operationToChoose_combo.setModel(new javax.swing.DefaultComboBoxModel(
new String[] { "关闭计算机", "重启计算机", "注销计算机" }));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
currentTime_lab,
javax.swing.GroupLayout.DEFAULT_SIZE,
268,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addGap(
46,
46,
46)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
setTime_btn)
.addGap(
30,
30,
30)
.addComponent(
cancelToSetTime_btn))
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
operationToChoose_combo,
0,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
timeToShutDownPc_txt,
javax.swing.GroupLayout.PREFERRED_SIZE,
75,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(
timeType_combox,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
timeToShutDown_lab,
javax.swing.GroupLayout.DEFAULT_SIZE,
268,
Short.MAX_VALUE)))
.addContainerGap()));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(
timeToShutDownPc_txt,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(
timeType_combox,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.Gr
Java编写的定时关机程序!只适用于Windows
需积分: 9 175 浏览量
2014-01-08
15:18:02
上传
评论 2
收藏 59KB RAR 举报
谁是机器人
- 粉丝: 39
- 资源: 6