1

我想知道如何将 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;

            }
4

1 回答 1

0

添加条件检查,并记住要明确您的问题。以下代码可能对您有所帮助

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*/);
    }
});
于 2013-11-02T13:20:59.243 回答