我们如何在java编程中添加时间延迟?
How can we add time delay in java programming?
我有这个程序:
import javax.swing.*;
public static void main()
{
try {
String stringyInp = JOptionPane.showInputDialog( null , "Enter your number" ) ;
int input = Integer.parseInt(stringyInp) ;
}catch(Exception e) {
JOptionPane.showMessageDialog(null ,"Enter only numerical values") ; //i want here to add a time delay of 3 seconds!How?
main();
}
System.out.print( FACTORIAL(input)) ;
}// instance variables - replace the example below with your own
public static int FACTORIAL(int number )
{
if (number == 0){
return 1 ;
}
else {
return FACTORIAL(number-1) * number ;
}
那么我们如何添加时间延迟,我们如何执行延迟3秒的指令??我想在此程序中添加 3 秒或 2 秒的延迟...
我想你可以使用这段代码。
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
我有这个程序:
import javax.swing.*;
public static void main()
{
try {
String stringyInp = JOptionPane.showInputDialog( null , "Enter your number" ) ;
int input = Integer.parseInt(stringyInp) ;
}catch(Exception e) {
JOptionPane.showMessageDialog(null ,"Enter only numerical values") ; //i want here to add a time delay of 3 seconds!How?
main();
}
System.out.print( FACTORIAL(input)) ;
}// instance variables - replace the example below with your own
public static int FACTORIAL(int number )
{
if (number == 0){
return 1 ;
}
else {
return FACTORIAL(number-1) * number ;
}
那么我们如何添加时间延迟,我们如何执行延迟3秒的指令??我想在此程序中添加 3 秒或 2 秒的延迟...
我想你可以使用这段代码。
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}