0

所以我有一个自定义按钮,一旦你选择它,你就不能取消选择它。我想检查我的程序上的 6 个按钮是否被选中,然后做一些事情。看起来很乱,但我认为这对我有用。请问有什么建议吗?

  if(bomb28.getModel().isPressed()){

    if(bomb37.getModel().isPressed()){
      if(bomb16.getModel().isPressed()){
        if(bomb17.getModel().isPressed()){
            if(bomb1.getModel().isPressed()){
            if(bomb3.getModel().isPressed()){

        jLabel3.setEnabled(true);
         jLabel3.setVisible(true);
        jLabel3.setText("YOU HAVE WON");
            }
            }

    }

    }  


    }

    }
4

1 回答 1

1
ArrayList<BombButton> buttons = new ArrayList<>();
buttons.add(bomb28);
buttons.add(bomb32);
// etc

private boolean areButtonsDown() {
   for( BombButton button : buttons ) {
      if( !button.getModel().isPressed() ) {
         return false;
      }
   }
   return true;
}
于 2014-12-11T16:56:12.600 回答