java60秒倒计时代码的简单介绍( 三 )


g_hour.drawLine(0,0,minute_a,minute_b);
g_hour.drawString("时",hour_a,hour_b);
}
}
catch(InterruptedException e){
return;
}
minute_a = (int)point_x[(i+1)%60];
minute_b = (int)point_y[(i+1)%60];
g_minute.setColor(Color.BLUE);
g_minute.drawLine(0,0,minute_a,minute_b);
g_minute.drawString("分",minute_a,minute_b);
i++; second = 0;
}
}
if(Thread.currentThread() == tHour){
int h = hour%12;
hour_a = (int)point_x[h*5 + minute/12];
hour_b = (int)point_y[h*5 + minute/12];
int i = h*5 + minute/12;
g_hour.drawLine(0,0,hour_a,hour_b);
g_hour.drawString("时",hour_a,hour_b);
while(true){
//第一次过12-minute%12分钟就前进一个刻度,以后每过12分钟前进一个刻度
try{
tHour.sleep(1000*60*12 - 1000*60*(minute%12) - second *1000);
minute = 0;
Color c = getBackground();
g_hour.setColor(c);
g_hour.drawLine(0,0,hour_a,hour_b);
g_hour.drawString("时",hour_a,hour_b);
}
catch(InterruptedException e){
return;
}
hour_a = (int)point_x[(i+1)%60];
hour_b = (int)point_y[(i+1)%60];
g_hour.setColor(Color.CYAN);
g_hour.drawLine(0,0,hour_a,hour_b);
g_hour.drawString("时",hour_a,hour_b);
i++;minute = 0;
}
}
}
}
求一个程序代码 swing做的java程序 就是倒计时60秒只要你输入正确的字就不关机 倒计CMD中有一个自动关机的语句,你可以在判断关机后调用这个CMD文件,如果你不知道CMD怎么写,追问
java 倒计时的程序import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class TimeThreadFrame extends JFrame{
// 定义组件
private JLabel lblTime;
private JTextField txtInput;
private JButton btnEnter;
// 构造方法
public TimeThreadFrame(){
// 设置窗体的相关属性
super("TimerThread");
this.setSize(300,200);
this.setLayout(null);
this.setLocation(100,50);
// 创建组件
this.lblTime = new JLabel("请输入倒计时时间");
this.lblTime.setBounds(30,20,200,30);
this.txtInput = new JTextField();
this.txtInput.setBounds(30,70,100,30);
this.btnEnter = new JButton("确定");
this.btnEnter.setBounds(150,70,70,30);
// 给JTextField注册监听
this.txtInput.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent ke) {
}
public void keyReleased(KeyEvent ke) {
}
public void keyTyped(KeyEvent ke) {
txtInput_KeyTyped(ke);
}
});
// 给JButton注册监听
this.btnEnter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
btnEnter_ActionPerformed(ae);
}
});
// 将各组件添加到窗体上
add(lblTime);
add(txtInput);
add(btnEnter);
// 显示窗体
this.setVisible(true);
}
// 输入时的事件处理,控制用户只能输入数字
public void txtInput_KeyTyped(KeyEvent ke){
if(ke.getKeyChar()'0' || ke.getKeyChar()'9'){
ke.setKeyChar('\0');
}
}
// 点击按钮时的事件处理,核心!
public void btnEnter_ActionPerformed(ActionEvent ae){
// 获得用户输入的倒计时时间
String strTime = this.txtInput.getText();
if(strTime.equals("")){
// 检测用户是否输入
this.lblTime.setText("您尚未输入,请输入!");
}
else{
Integer time = Integer.parseInt(strTime);
// 创建线程
TimeThread tt = new TimeThread(this.lblTime,time);

推荐阅读