十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
定时开机是BIOS设置的。
成都创新互联主营合浦网站建设的网络公司,主营网站建设方案,重庆APP软件开发,合浦h5微信小程序搭建,合浦网站营销推广欢迎合浦等地区企业咨询
定时关机这个好写。。。。
启动时检测一次当前时间,算出距离目标时间的值。
然后线程休眠这么长时间。
然后执行控制台命令,调用windows系统自带的关机命令就可以了。
java调用控制台的关机命令如下
Runtime.getRuntime().exec("shutdown -s");
lang包下的,直接可以用~
系统是winXP+JVM1.5
以下是给你修改过的 ,还加了一个取消功能,看看。
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class ClockFrame extends JFrame {
private JComboBox hourBox, minuteBox, secondBox;
private int hour, minute, second, totalSeconds, currentSeconds;
private long argue;
private GregorianCalendar calendar;
private boolean change = true;
private static final int WIDTH = 200;
private static final int HEIGHT = 150;
public ClockFrame() {
setTitle("关机定时");
setSize(200, 150);
Container contentPanel = getContentPane();
JPanel timePanel = new JPanel();
timePanel.setLayout(new GridLayout(4, 2));
JLabel minuteLable = new JLabel("设置分钟");
timePanel.add(minuteLable);
minuteBox = new JComboBox();
timePanel.add(minuteBox);
for (int i = 0; i 60; i++) {
minuteBox.addItem(i);
}
minuteBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
minute = ((Integer) minuteBox.getSelectedItem()).intValue();
}
});
JLabel secondLable = new JLabel("设置秒钟");
timePanel.add(secondLable);
secondBox = new JComboBox();
timePanel.add(secondBox);
for (int i = 0; i 60; i++) {
secondBox.addItem(i);
}
secondBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
second = ((Integer) secondBox.getSelectedItem()).intValue();
}
});
contentPanel.add(timePanel, BorderLayout.CENTER);
JButton check = new JButton("确定");
contentPanel.add(check, BorderLayout.SOUTH);
check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JButton check=(JButton) evt.getSource();
if (check.getText().equals("确定")) {
calendar = new GregorianCalendar();
int currentSeconds = calendar.get(Calendar.HOUR_OF_DAY)
* 3600 + calendar.get(Calendar.MINUTE) * 60
+ calendar.get(Calendar.SECOND);
totalSeconds = hour * 3600 + minute * 60 + second;
if (totalSeconds - currentSeconds = 0) {
argue = (totalSeconds - currentSeconds) * 1000;
JOptionPane.showMessageDialog(ClockFrame.this,
"您设置的时间为 " + hour + ":" + minute + ":" + second
+ "\n程序将在后台运行,并在此时自动关闭计算机!", "设置成功",
JOptionPane.INFORMATION_MESSAGE);
hideFrame();
}
try {
// Thread.sleep(argue);//这句没用
Runtime.getRuntime().exec(
"shutdown.exe -s -c \"我要关机了噢!不好意思!\" -t "
+ totalSeconds);
check.setText("取消");
} catch (Exception e) {
e.printStackTrace();
}
}else{
try {
Runtime.getRuntime().exec("shutdown.exe -a");
check.setText("确定");
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
private void hideFrame() {
this.setVisible(false);
}
public static void main(String[] args) {
JFrame frame = new ClockFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
frame.show();
}
}
手机关机代码:
In frameworks/base/services/java/com/android/server/BatteryService。
Intent intent = new Intent(Intent。ACTION_REQUEST_SHUTDOWN);
intent。putExtra(Intent。EXTRA_KEY_CONFIRM, false);
intent。setFlags(Intent。FLAG_ACTIVITY_NEW_TASK);
mContext。startActivity(intent);
手机充电的预防措施:
给手机充电的最好方式是一有机会就充电,每次充一点电。哪怕只是几分钟也行,零星时间充电不会损害电池。
不要等电池电量完全耗尽后再给手机充电。所谓的深度放电即等电池电量几乎耗尽时再给它充电对电池损耗极大。
手机电池一边输入,一边输出,不仅会耗双倍的电,对电池性能造成损坏,严重的甚至可能会导致手机爆炸。