自己看了下,逻辑没什么问题,可是运行后点击开始按钮,就是无法运行,求大神看看
/**
*
*/
package testjavase.homework;
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* @author GT
*create date:2015年7月31日 上午11:23:09
*/
public class AutoClose implements ActionListener{
private JFrame frame = new JFrame("AutoClose");
private JLabel label = new JLabel("02:00:00",JLabel.CENTER);
private static long time = 2*60*60;
private Panel panel = new Panel();
private Button b_start = new Button("开始");
/**
*
*/
public AutoClose() {
// TODO Auto-generated constructor stub
label.setFont(new Font("Arial",Font.BOLD,50));
frame.add(label);
frame.add(panel,"South");
panel.add(b_start);
frame.setSize(300, 200);
frame.setLocation(200, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//正常退出程序
b_start.addActionListener(this);
}
public void go(){
while(time!=0){
label.setText(getTime());
time--;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.exit(0);//倒计时结束后自动结束程序
}
public String getTime(){
int hour;
int minute;
int second;
hour = (int) (time/(60*60));
minute = (int) (time%(60*60)/60);
second = (int) (time%(60*60)%60);
return timeTransForm(hour)+":"+timeTransForm(minute)+":"+timeTransForm(second);
}
public String timeTransForm(int num){
return (num<10? "0":"")+String.valueOf(num);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new AutoClose();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.go();
}
}
/**
*
*/
package testjavase.homework;
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* @author GT
*create date:2015年7月31日 上午11:23:09
*/
public class AutoClose implements ActionListener{
private JFrame frame = new JFrame("AutoClose");
private JLabel label = new JLabel("02:00:00",JLabel.CENTER);
private static long time = 2*60*60;
private Panel panel = new Panel();
private Button b_start = new Button("开始");
/**
*
*/
public AutoClose() {
// TODO Auto-generated constructor stub
label.setFont(new Font("Arial",Font.BOLD,50));
frame.add(label);
frame.add(panel,"South");
panel.add(b_start);
frame.setSize(300, 200);
frame.setLocation(200, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//正常退出程序
b_start.addActionListener(this);
}
public void go(){
while(time!=0){
label.setText(getTime());
time--;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.exit(0);//倒计时结束后自动结束程序
}
public String getTime(){
int hour;
int minute;
int second;
hour = (int) (time/(60*60));
minute = (int) (time%(60*60)/60);
second = (int) (time%(60*60)%60);
return timeTransForm(hour)+":"+timeTransForm(minute)+":"+timeTransForm(second);
}
public String timeTransForm(int num){
return (num<10? "0":"")+String.valueOf(num);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new AutoClose();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
this.go();
}
}