【问题标题】:Multiple Jtextfields to one Jbutton多个 Jtextfields 到一个 Jbutton
【发布时间】:2012-10-09 09:03:08
【问题描述】:

我想知道如何将 4 个单独的 Jtextfields 放入一个 Jbutton 中,如果您在文本字段中输入 3 个值并按下按钮,它们将在第 4 个文本字段中显示新值。

btnDoIt.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        double a;
        a = Double.parseDouble(txtA.getText());
        txtOutput.setText("The root(s) of the equation is(are): " + a);
        double b;

            }

【问题讨论】:

    标签: jbutton jtextfield


    【解决方案1】:

    添加条件检查,记得把你的问题说清楚。以下代码可能对您有所帮助

    btnDoIt.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            //get text from first 3 textfields
            String s1 = txtA.getText();
            String s2 = txtB.getText();
            String s3 = txtC.getText();
            //make sure strings aren't empty
            if(s1.isEmpty() || s2.isEmpty() || s3.isEmpty()){
                return;
            }
            //set text of final textfield
            txtOutput.setText(/*Your operation here*/);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 2014-05-19
      • 1970-01-01
      • 2014-10-12
      • 2017-02-10
      • 2012-11-27
      • 1970-01-01
      • 2015-05-22
      相关资源
      最近更新 更多