JavaJButton只需要工作一次

JavaJButton只需要工作一次,java,jbutton,Java,Jbutton,我不明白,我怎么能做到这一点,若点击按钮,它只会检查一次Playerlevel和升级。直到没有足够的钱 1.试试看 if(ae.getActionCommand().equals(“升级LVL”){ 如果(car.Playerlevel==1){ 如果(car.money>=2){ 汽车.货币-=2; car.Playerlevel+=1; JOptionPane.showMessageDialog(空,“您已获得1个玩家级别”,“祝贺”,JOptionPane.INFORMATION_消息);

我不明白,我怎么能做到这一点,若点击按钮,它只会检查一次Playerlevel和升级。直到没有足够的钱

1.试试看

if(ae.getActionCommand().equals(“升级LVL”){
如果(car.Playerlevel==1){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(空,“您已获得1个玩家级别”,“祝贺”,JOptionPane.INFORMATION_消息);
}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要100美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}           
如果(car.Playerlevel==2){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得2个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要200美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==3){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得3个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要300美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==4){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得4个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要400美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==5){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得5个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要500美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==6){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得6个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要600美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==7){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得7个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要700美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==8){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得8个玩家级别”,“祝贺”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要800美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==9){
如果(car.money>=2){
汽车.货币-=2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您已获得9个玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
如果(车钱<2){
JOptionPane.showMessageDialog(null,“您没有足够的钱。此升级需要900美元”,“没有钱”,JOptionPane.ERROR_MESSAGE);}
}
如果(car.Playerlevel==10){
JOptionPane.showMessageDialog(null,“您已获得最高玩家级别”,“恭喜”,JOptionPane.INFORMATION_MESSAGE);}
}
2.试试看

if(ae.getActionCommand().equals(“升级LVL”){
对于(int i=0;i=i*2){
car.money-=i*2;
car.Playerlevel+=1;
JOptionPane.showMessageDialog(null,“您购买了”+i+“玩家级别”。,“Congrelations”,JOptionPane.INFORMATION_MESSAGE);}
否则{
JOptionPane.showMessage
 if(ae.getActionCommand().equals("Upgrade LVL")) {  
                if (car.Playerlevel == 1){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 1 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);
                        }
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 100", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }           
                if (car.Playerlevel == 2){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 2 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 200", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 3){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 3 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 300", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 4){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 4 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 400", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 5){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 5 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 500", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 6){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 6 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 600", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 7){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 7 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 700", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 8){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 8 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 800", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 9){
                    if (car.money >= 2){
                        car.money -= 2;
                        car.Playerlevel +=1;
                        JOptionPane.showMessageDialog (null, "You have gained 9 Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}
                    if (car.money < 2){
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 900", "No Money", JOptionPane.ERROR_MESSAGE);}                
                    }
                if (car.Playerlevel == 10){
                        JOptionPane.showMessageDialog (null, "You have gained MAX Player Level", "Congralations", JOptionPane.INFORMATION_MESSAGE);}                            
            }
if(ae.getActionCommand().equals("Upgrade LVL")) {           
            for (int i =0; i <11; i++){                 
                   if (car.Playerlevel == i){
                    if (car.money >= i*2){
                        car.money -= i*2;
                        car.Playerlevel +=1;                   
                        JOptionPane.showMessageDialog (null, "You have purchased " + i + " Player level.", "Congralations", JOptionPane.INFORMATION_MESSAGE);}                          
                    else{                           
                        JOptionPane.showMessageDialog (null, "You dont have enought money. This Upgrade costs 100*lvl", "No Money", JOptionPane.ERROR_MESSAGE);}               
                   }
            }
        }
 for (int i =0; i <11; i++)
 for (int i=10; i>= 0; i--)