如何在循环中从JTextField读取信息

时间:2018-04-26 22:46:47

标签: java for-loop jtextfield

如何阅读JTextField的信息?

private class Caverage implements ActionListener {
    public void actionPerformed(ActionEvent AVR) {
        int num1 =Integer.parseInt(num_ofC.getText());
        JTextField[] coursg = new JTextField[num1];

        c.add(CAV);

        // Add JTextField if i Click the jbutton Click
        if (AVR.getSource() == Click) {
            for (int i =0;i<coursg.length;i++) {
                coursg[i] = new JTextField("",17);
                c.add(coursg[i]);
                setSize(700,240);
            }

            // Read JTextField if i click the jbutton CAV
            if (AVR.getSource() == CAV) {
                for (int i =0;i<coursg.length;i++) {
                    int num2 =Integer.parseInt(coursg[i].getText());
                    System.out.println(num2);
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

检查括号。您的第二个if位于第一个if内,而AVR.getSource()不能同时位于ClickCVR