怎么让JAVA循环一秒一秒的执行
package靖哥哥;importjava.util.Random;publicclassPlayextendsGame{Play(Strings){super(s);/...
package 靖哥哥;
import java.util.Random;
public class Play extends Game{
Play(String s) {
super(s);
// TODO Auto-generated constructor stub
}
static void A(Fight a,Fight b){
int c;
Random random=new Random();
while(a.HP>0&&b.HP>0){
c=random.nextInt(6)+2;
switch(c){
case 1:{
T9.setText(a.name+"被"+b.name+"和谐");
a.HP-=70;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 2:{
T9.setText(a.name+"被"+b.name+"狂揍");
b.HP=b.HP-80;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 3:{
T9.setText(a.name+"血量增加");
a.HP=a.HP+150;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 4:{
T9.setText(b.name+"血量增加");
b.HP=b.HP+100;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 5:{
T9.setText(a.name+"被"+b.name+"狂扇");
a.HP=a.HP-200;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 6:{
T9.setText(a.name+"被"+a.name+"狂扇");
b.HP=b.HP-200;
Area.append(b.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
}
}
if(a.HP>0){
Area.append(a.name+""+b.name+"\n");
}
else if(b.HP>0){
Area.append(b.name+"完胜"+a.name+"\n");
}
}
}
我是才学JAVA,想让这个一秒一秒的显示出来 可是用了Thread.sleep整个窗口会锁死,请问详细的该怎么办啊 展开
import java.util.Random;
public class Play extends Game{
Play(String s) {
super(s);
// TODO Auto-generated constructor stub
}
static void A(Fight a,Fight b){
int c;
Random random=new Random();
while(a.HP>0&&b.HP>0){
c=random.nextInt(6)+2;
switch(c){
case 1:{
T9.setText(a.name+"被"+b.name+"和谐");
a.HP-=70;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 2:{
T9.setText(a.name+"被"+b.name+"狂揍");
b.HP=b.HP-80;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 3:{
T9.setText(a.name+"血量增加");
a.HP=a.HP+150;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 4:{
T9.setText(b.name+"血量增加");
b.HP=b.HP+100;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 5:{
T9.setText(a.name+"被"+b.name+"狂扇");
a.HP=a.HP-200;
Area.append(a.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
case 6:{
T9.setText(a.name+"被"+a.name+"狂扇");
b.HP=b.HP-200;
Area.append(b.name+"的血量为"+a.HP+" "+b.name+"的血量为"+b.HP+"\n");
break;
}
}
}
if(a.HP>0){
Area.append(a.name+""+b.name+"\n");
}
else if(b.HP>0){
Area.append(b.name+"完胜"+a.name+"\n");
}
}
}
我是才学JAVA,想让这个一秒一秒的显示出来 可是用了Thread.sleep整个窗口会锁死,请问详细的该怎么办啊 展开
2个回答
展开全部
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询