该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import java.awt.Rectangle;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class TimerFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JTextField jTextField = null;
private JButton jButton = null;
private JButton jButton1 = null;
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(114, 21, 171, 33));
}
return jTextField;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(38, 74, 111, 30));
jButton.setText("开始定时");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
Date timeToRun = sdf.parse(jTextField.getText());
Timer timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
try{
Runtime.getRuntime().exec("shutdown.exe -s -f -t 0");
JOptionPane.showMessageDialog(null,"定时成功");
}catch(IOException ex){
ex.printStackTrace();
}
}
}, timeToRun);
}catch(Exception ex){
ex.printStackTrace();
}
}
});
}
return jButton;
}
/**
* This method initializes jButton1
*
* @return javax.swing.JButton
*/
private JButton getJButton1() {