这是problem.i不能点击按钮,而倒计时running.i必须等到倒计时停止。我的问题是如何让倒计时运行在background.or任何建议,请帮助我!如何使倒计时运行在后台使用eclipse
public static void main(String args[]){
scrbutton myWindow = new scrbutton(); //set window design
myWindow.setSize(300,70);
myWindow.setVisible(true);
myWindow.setResizable(false);
}
public scrbutton() {
super("Clicker"); //Title
setLayout(new FlowLayout());
addWindowListener(this);
add(kotak);
add(kotak2); //add and design you components
add(kotak3);
add(enter);
enter.addActionListener(this);
kotak.setText("0");
kotak2.setText("Times remaining: 60");
kotak.setEditable(false);
kotak2.setEditable(false);
kotak3.setEditable(false);
}
public void actionPerformed(ActionEvent e) //What will run through the program?
{
click++;
kotak.setText("\r"+click); //display number of click
if (click >=10){
kotak3.setText("You Win!");
enter.setEnabled(false);
}else{
kotak3.setText("try again");
}
for(int x=60; x>=0; x--)
{System.out.print(x+"\r"); // use print than println if you use (/r).
try {Thread.sleep(100);} // 1000ms=1second thus its sleep(delay) 1 second between each iteration.
catch (InterruptedException e1){}
}
}
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
}
我使用线程和它的完美运行!谢谢bro – hizers