把getText()写在监听里就好。
像这样:
test.button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { temp1[0] =test.textField.getText(); System.out.println("总数为:"+temp1[0]); } catch (Exception exception) { exception.printStackTrace(); } } });