小编use*_*212的帖子

在JavaFX中启用/禁用按钮

如何在一定条件下禁用按钮?例如,我有许多文本字段和按钮,当这些文本字段为空时,应禁用其中一个按钮.我已经有了这个代码.

if(txtID.getText().isEmpty()&&txtG.getText().isEmpty()
            &&txtBP.getText().isEmpty()&&txtD.getText().isEmpty()
            &&txtSP.getText().isEmpty()&&txtCons.getText().isEmpty()){
       btnAdd.setDisable(true);
       }
else{
btnAdd.setDisable(false);
}
Run Code Online (Sandbox Code Playgroud)

有更简单的方法吗?此外,如果我在这些区域添加文本,按钮是否应重新启用它自己?

java javafx

4
推荐指数
1
解决办法
2万
查看次数

如果陈述逻辑不起作用

所以我有这两个类叫做装运和保险,一个计算运费的价格,另一个加上保险.出货逻辑工作正常,但由于某种原因保险类中的if语句不起作用,我不知道发生了什么.保险费用的输出总是2.45.它为什么这样做?

装运等级:

  package theshipment;

  public class Shipment extends Main {
      protected double weight = Double.parseDouble(savedArgs[1]);
      protected double shippingCost;
      protected double methodCost;
      protected String method = savedArgs[2];

      public void calculateShippingCost(){

        if (weight<=10||weight>=1){
            if (method.equalsIgnoreCase("T"))
                methodCost = weight * 3.00;
            else if (method.equalsIgnoreCase("A"))
                methodCost = weight * 4.00;
            else if (method.equalsIgnoreCase("M"))
                methodCost = weight * 2.00;
            else{}
        }else if (weight<=20||weight>=10.1){
            if (method.equalsIgnoreCase("T"))
                methodCost = weight * 2.45;
            else if (method.equalsIgnoreCase("A"))
                methodCost = weight * 3.00;
            else if (method.equalsIgnoreCase("M"))
                methodCost = weight * …
Run Code Online (Sandbox Code Playgroud)

java if-statement

0
推荐指数
1
解决办法
86
查看次数

标签 统计

java ×2

if-statement ×1

javafx ×1