1、aTextControlTheInput是A文本框的KeyListener时间,aTextField是A文本框,bTextField是B文本框
public class aTextControlTheInput extends KeyAdapter { public void keyTyped(KeyEvent e) { String key="0123456789"+(char)8; if(key.indexOf(e.getKeyChar())<0){ e.consume(); } char c = e.getKeyChar(); String text = aTextField.getText(); if(StringUtils.isEmpty(text)) { if(c != '1') { bTextField.setText("1"); bTextField.setEnabled(false); }else { bTextField.setEnabled(true); } }else { if(c != '1') { bTextField.setText("1"); bTextField.setEnabled(false); }else { bTextField.setEnabled(true); } } } @Override public void keyPressed(KeyEvent e) { System.out.println("B="+aTextField.getText()); } @Override public void keyReleased(KeyEvent e) { String key="0123456789"+(char)8; if(key.indexOf(e.getKeyChar())<0){ e.consume(); } String text = aTextField.getText(); if(StringUtils.isNotEmpty(text)) { if(text.equals("1")) { bTextField.setEnabled(true); }else { bTextField.setText("1"); bTextField.setEnabled(false); } }else { bTextField.setEnabled(true); } } }