如题,比如我输入222222,
就会返回数值6

解决方案 »

  1.   

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class T {
    public static void main(String[] args) {
    JFrame f = new JFrame();
    final JTextField tf = new JTextField();
    tf.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
    System.out.println(tf.getText().length());
    tf.setText("");
    }
    });
    f.add(tf);
    f.pack();
    f.setVisible(true);
    }
    }
      

  2.   

    getDocument().getLength();orgetText().length();