Results 1 to 6 of 6
  1. #1
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Event pump exceptions.

    Hello,
    I have a frame with input fields, supposedly checked with event listeners, if the textfields are more than 2 chars long and one text field that must be a float point entry, after meeting the conditions, it`s supposed to unlock an add button.. It`s OK. WOrking. But here is an issue, when I input non float point number, and hold backspace to quickly remove it - the program bugs. Not freeze. Just the floating point field gets error inputs. In err console I have this tons of exceptions:

    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1241)
    at java.lang.Float.valueOf(Float.java:417)
    at com.ilian.MainFrame$2$3.tellMe(MainFrame.java:383)
    at com.ilian.MainFrame$2$3.insertUpdate(MainFrame.jav a:379)
    at javax.swing.text.AbstractDocument.fireInsertUpdate (AbstractDocument.java:202)
    at javax.swing.text.AbstractDocument.handleInsertStri ng(AbstractDocument.java:749)
    at javax.swing.text.AbstractDocument.insertString(Abs tractDocument.java:708)
    at javax.swing.text.PlainDocument.insertString(PlainD ocument.java:130)
    at javax.swing.text.AbstractDocument.replace(Abstract Document.java:670)
    at javax.swing.text.JTextComponent.replaceSelection(J TextComponent.java:1379)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedA ction.actionPerformed(DefaultEditorKit.java:884)
    at javax.swing.SwingUtilities.notifyAction(SwingUtili ties.java:1661)
    at javax.swing.JComponent.processKeyBinding(JComponen t.java:2870)
    at javax.swing.JComponent.processKeyBindings(JCompone nt.java:2917)
    at javax.swing.JComponent.processKeyEvent(JComponent. java:2833)
    at java.awt.Component.processEvent(Component.java:628 2)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1895)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:762)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:1027)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:899)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:727)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4731)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:729)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:702)
    at java.awt.EventQueue$4.run(EventQueue.java:700)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 699)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:91)
    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "jhjk"
    at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1241)
    at java.lang.Float.valueOf(Float.java:417)
    at com.ilian.MainFrame$2$3.tellMe(MainFrame.java:383)
    at com.ilian.MainFrame$2$3.insertUpdate(MainFrame.jav a:379)
    at javax.swing.text.AbstractDocument.fireInsertUpdate (AbstractDocument.java:202)
    at javax.swing.text.AbstractDocument.handleInsertStri ng(AbstractDocument.java:749)
    at javax.swing.text.AbstractDocument.insertString(Abs tractDocument.java:708)
    at javax.swing.text.PlainDocument.insertString(PlainD ocument.java:130)
    at javax.swing.text.AbstractDocument.replace(Abstract Document.java:670)
    at javax.swing.text.JTextComponent.replaceSelection(J TextComponent.java:1379)
    at javax.swing.text.DefaultEditorKit$DefaultKeyTypedA ction.actionPerformed(DefaultEditorKit.java:884)
    at javax.swing.SwingUtilities.notifyAction(SwingUtili ties.java:1661)
    at javax.swing.JComponent.processKeyBinding(JComponen t.java:2870)
    at javax.swing.JComponent.processKeyBindings(JCompone nt.java:2917)
    at javax.swing.JComponent.processKeyEvent(JComponent. java:2833)
    at java.awt.Component.processEvent(Component.java:628 2)
    at java.awt.Container.processEvent(Container.java:222 9)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4861)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.KeyboardFocusManager.redispatchEvent(Keyb oardFocusManager.java:1895)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:762)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:1027)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:899)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:727)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4731)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2287)
    at java.awt.Window.dispatchEventImpl(Window.java:2719 )
    at java.awt.Component.dispatchEvent(Component.java:46 87)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:729)
    at java.awt.EventQueue.access$200(EventQueue.java:103 )
    at java.awt.EventQueue$3.run(EventQueue.java:688)
    at java.awt.EventQueue$3.run(EventQueue.java:686)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:702)
    at java.awt.EventQueue$4.run(EventQueue.java:700)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 699)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:91)

    Can somebody tells me why it is so messed up?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,539
    Rep Power
    5

    Default Re: Event pump exceptions.

    I can't give you specifics right now because it has been a while since I did this. But I have done it by
    using the Document class and processing characters as they are typed (similar to raw mode input of *nix machines).
    Anyway, I kept looking for a specific input terminator to end the input. During input for each character I would catch
    parseDouble exceptions and take appropriate actions until I had a proper value. There may be a more straight forward
    way but this worked.


    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Event pump exceptions.

    So the issue is from the parseFloat() going so fast? I tough it would be the lightest of all... besides whatever I do, maybe I sholud try Regex with "\\d\\.\\d{1,4}" to match the getText()? Any way... is your suggestion based on C-like process of every char? And that will solve it?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: Event pump exceptions.

    Use a DocumentFilter, and ensure that all Swing code is executed on the EDT.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Event pump exceptions.

    I`ve saw your reply now... I`ve came with a simple, lightweight code that fixed the issue:

    Java Code:
    public void tellMe(DocumentEvent e ) {
    				char[] l = new char[perc1.getText().length()];
    				l = perc1.getText().toCharArray();
    				int fpcheck=0;
    				for (int i=0; i < l.length; i++ ) {
    					if ( fpcheck > 1 ) 
    					    addButton1.setEnabled(false);
    					if ( (l[i] < '0'|| l[i] > '9') && l[i] != '.' ) 
    					    addButton1.setEnabled(false);
    					if ( l[i] == '.' ) fpcheck++;
    				}
    				System.err.println("REACHED END");
    			}
    How is that?

  6. #6
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: Event pump exceptions.

    Here is a small shot of what was expected and it is working now. Hope it wont provide bugs. Added some continue statements to my above code and it became a working example. Kind of old C way but... still working.
    Attached Thumbnails Attached Thumbnails Event pump exceptions.-screenshot-05272013-08-38-04-am.png   Event pump exceptions.-screenshot-05272013-08-38-33-am.png  

Similar Threads

  1. exceptions
    By ii88xix88ii in forum JCreator
    Replies: 6
    Last Post: 03-12-2013, 03:07 PM
  2. help with exceptions
    By dawnMist in forum New To Java
    Replies: 31
    Last Post: 11-15-2012, 10:09 AM
  3. WOW need help with Exceptions
    By starplayerrob in forum New To Java
    Replies: 4
    Last Post: 12-12-2011, 10:49 AM
  4. checking for an event during an event
    By infinity in forum AWT / Swing
    Replies: 22
    Last Post: 04-09-2009, 01:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •