基本上,我正在尝试为酒店预订表格,有2种选择:
这是场景:https://imgur.com/a/5GdgFAg
我一直在尝试创建一个文本字段“ Nombre de lits”。无论何时选中单选按钮“ couple”,都应禁用它。当我单击“ Litsseparés”单选按钮时,应该启用它。但是,即使我单击该按钮,文本字段仍保持禁用状态。
我一直在努力使它工作,但是没有运气。这是我的代码:
package controleur;
import java.time.LocalDate; import java.time.format.DateTimeFormatter;
import accesBD.ClientDAO; import javafx.beans.binding.Bindings; import javafx.beans.binding.BooleanBinding; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.DatePicker; import javafx.scene.control.RadioButton; import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import metier.Client;
public class ReservationControleur {
private ClientDAO bd = new ClientDAO();
@FXML
private TextField nom;
@FXML
private TextField prenom;
@FXML
private TextField nationalite;
@FXML
private DatePicker datedebut;
@FXML
private TextField numtel;
@FXML
private DatePicker datefin;
@FXML
private RadioButton couple;
@FXML
private RadioButton litss;
@FXML
private RadioButton douche;
@FXML
private RadioButton bain;
@FXML
private TextField nbrlits;
@FXML
private RadioButton standard;
@FXML
private RadioButton inclusive;
@FXML
private RadioButton vip;
@FXML
private Button valider;
@FXML
private Button anuuler;
private ToggleGroup group = new ToggleGroup();
private ToggleGroup group1 = new ToggleGroup();
@FXML private void isClicked(ActionEvent event){
}
public void initialize() {
datedebut.setValue(LocalDate.now());
couple.setToggleGroup(group);
couple.setSelected(true);
litss.setToggleGroup(group);
douche.setToggleGroup(group1);
bain.setToggleGroup(group1);
douche.setSelected(true);
if(couple.isSelected())
nbrlits.setDisable(true);
else
nbrlits.setDisable(false);
}
@FXML
void confirmer(ActionEvent event) {
int ntel = Integer.parseInt(numtel.getText());
Client c = new Client(nom.getText(), prenom.getText(), nationalite.getText(), ntel);
bd.add(c);
}
@FXML
void remiseazero(ActionEvent event) {
}
}
有人可以帮忙吗?
答案 0 :(得分:1)
检查哪个RadioButton被选中的代码仅执行一次-初始化ReservationControleur时,这不是您所需要的。
您希望每次选择“ couple”单选按钮时将“ nbrlits” TextView的状态更改为“ disabled”,因此需要将这两个属性绑定在一起。
更改此:
M3PL1234
M3PL368182
对此:
if(couple.isSelected())
nbrlits.setDisable(true);
else
nbrlits.setDisable(false);
}