hi, The problem is related to the handling of the Textfield. I am implementing the KeyTyped method of the KeyListerner Interface. Now whenever a key is pressed and the KeyTyped method is fired. NOw extracting the contents of the TextField at that moment does not pass the updated TextField contents rather the old values which creates lot of problems in subsequent handling of the code. I am listing down my KeyTyped method so that the problem becomes clear. Here Inodestf is a JTextField Problem is the contents of String s which gets the old value of the TextField after the Key is pressed. Suggest a solution to get the updated value in the String s after the KeyListerner event is fired. public void keyTyped(KeyEvent ke) { try { if ( (ke.getSource() == Inodestf) ) { char c=ke.getKeyChar(); String s = Inodestf.getText().trim(); //Contents of TextField not updated if (Character.isISOControl(c)) // for non printable chars... { lv.numinputneurons = Integer.parseInt(s); }else // for printable chars... { lv.numinputneurons = Integer.parseInt(s+c); currInodes = lv.numinputneurons; } }
Manfred Leonhardt
Ranch Hand
Joined: Jan 09, 2001
Posts: 1492
posted
0
Hi Remi, I think you might be better to look into DocumentListeners when using JTextFields.
The java.awt.TextField could be monitored for changes by adding a TextListener for TextEvent's. In the JTextComponent based components, changes are broadcasted from the model via a DocumentEvent to DocumentListeners. The DocumentEvent gives the location of the change and the kind of change if desired. The code fragment might look something like: DocumentListener myListener = ??; JTextField myArea = ??; myArea.getDocument().addDocumentListener(myListener);