java 提醒小工具_【JAVA】一个简单的定时提醒小程序
[Java] 純文本查看 復(fù)制代碼import javax.swing.JOptionPane;
public class Test {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "程序啟動(dòng)!");
System.out.println("程序啟動(dòng)!");
int setTime = setTime();
if(-1 != setTime) {
System.out.println("開(kāi)始計(jì)時(shí)!");
long tmil = 60 * 1000 * setTime;
while (true) {
try {
Thread.sleep(tmil);
int confirmDialog = JOptionPane.showConfirmDialog(null, "叮叮叮~", "", JOptionPane.YES_NO_OPTION);
if(1 == confirmDialog) {
break;
}
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
}
JOptionPane.showMessageDialog(null, "程序退出!");
System.out.println("程序退出!");
}
public static int setTime() {
String time = JOptionPane.showInputDialog("輸入間隔時(shí)間(分鐘0-1440):");
if(time == null) {
return -1;
}
int i = 5;
try {
i = Integer.parseInt(time);
if(i < 1) {
throw new Exception("時(shí)間輸入范圍不正確!");
}
if(i > 1440) {
i = 1440;
throw new Exception("時(shí)間輸入范圍不正確!");
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "時(shí)間輸入錯(cuò)誤!");
i = setTime();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
i = setTime();
}
return i;
}
}
總結(jié)
以上是生活随笔為你收集整理的java 提醒小工具_【JAVA】一个简单的定时提醒小程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 平面解析几何----椭圆中焦中三角形的最
- 下一篇: 2020幻影围棋 第三天围棋规则模块(一