定時(shí)開機(jī)是BIOS設(shè)置的。
成都創(chuàng)新互聯(lián)主營(yíng)合浦網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP軟件開發(fā),合浦h5微信小程序搭建,合浦網(wǎng)站營(yíng)銷推廣歡迎合浦等地區(qū)企業(yè)咨詢
定時(shí)關(guān)機(jī)這個(gè)好寫。。。。
啟動(dòng)時(shí)檢測(cè)一次當(dāng)前時(shí)間,算出距離目標(biāo)時(shí)間的值。
然后線程休眠這么長(zhǎng)時(shí)間。
然后執(zhí)行控制臺(tái)命令,調(diào)用windows系統(tǒng)自帶的關(guān)機(jī)命令就可以了。
java調(diào)用控制臺(tái)的關(guān)機(jī)命令如下
Runtime.getRuntime().exec("shutdown -s");
lang包下的,直接可以用~
系統(tǒng)是winXP+JVM1.5
以下是給你修改過的 ,還加了一個(gè)取消功能,看看。
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("關(guān)機(jī)定時(shí)");
setSize(200, 150);
Container contentPanel = getContentPane();
JPanel timePanel = new JPanel();
timePanel.setLayout(new GridLayout(4, 2));
JLabel minuteLable = new JLabel("設(shè)置分鐘");
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("設(shè)置秒鐘");
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,
"您設(shè)置的時(shí)間為 " + hour + ":" + minute + ":" + second
+ "\n程序?qū)⒃诤笈_(tái)運(yùn)行,并在此時(shí)自動(dòng)關(guān)閉計(jì)算機(jī)!", "設(shè)置成功",
JOptionPane.INFORMATION_MESSAGE);
hideFrame();
}
try {
// Thread.sleep(argue);//這句沒用
Runtime.getRuntime().exec(
"shutdown.exe -s -c \"我要關(guān)機(jī)了噢!不好意思!\" -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();
}
}
手機(jī)關(guān)機(jī)代碼:
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);
手機(jī)充電的預(yù)防措施:
給手機(jī)充電的最好方式是一有機(jī)會(huì)就充電,每次充一點(diǎn)電。哪怕只是幾分鐘也行,零星時(shí)間充電不會(huì)損害電池。
不要等電池電量完全耗盡后再給手機(jī)充電。所謂的深度放電即等電池電量幾乎耗盡時(shí)再給它充電對(duì)電池?fù)p耗極大。
手機(jī)電池一邊輸入,一邊輸出,不僅會(huì)耗雙倍的電,對(duì)電池性能造成損壞,嚴(yán)重的甚至可能會(huì)導(dǎo)致手機(jī)爆炸。