clockthread.java
来自「使用java的exec方法调用windows的命令提示符」· Java 代码 · 共 70 行
JAVA
70 行
import java.io.IOException;
public class clockthread extends Thread{
int time;
String process;
boolean stopflag,startflag;
public clockthread( int time,String process){
this.time=time;
this.process=process;
stopflag=true;//控制计数器是否运行,其为TURE说明计数器停止(即游戏程序没有运行)
startflag=false;//保证只运行线程的方法Start()一次,防止多次调用Start()发生错误
}
public void run(){
while(true){
while(!stopflag){
clock();
if(time!=1)
{
time--;
}
try {
sleep(1000);
}
catch(InterruptedException e)
{
return;
}
}
try {
sleep(1000);
}
catch(InterruptedException e)
{
return;
}
}
}
public void clock(){
if(time==5){
System.out.println("还差5分钟结束");
}
else if(time==1){
System.out.println("时间到关闭");
try{
Process p = Runtime.getRuntime().exec("taskkill /F /im IPMsg(文件传输).exe");
//p.destroy();
}catch(Exception e) {
e.printStackTrace();
}
}
/*switch(time){
case 5:
System.out.println("还差5分钟结束");break;
case 1:
System.out.println("时间到关闭");
try{
Process p = Runtime.getRuntime().exec("taskkill /F /im IPMsg(文件传输).exe");
//p.destroy();
}catch(Exception e) {
e.printStackTrace();
}
break;
default :
break;
} */
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?