Results 1 to 4 of 4
  1. #1
    blustar angel is offline Member
    Join Date
    Aug 2012
    Posts
    17
    Blog Entries
    1
    Rep Power
    0

    Default problem with key typed event of textfeild

    i need to write a code to enter only numerical keys. i am using key typed event.
    here is my code,
    Java Code:
     char ch=evt.getKeyChar();
            if(!((char>='0'&& char<='9')||ch == KeyEvent.VK_BACK_SPACE||ch == evt.VK_DELETE))
            
        
            evt.consume();
    i am getting error at line 2(if(!..

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: problem with key typed event of textfeild

    Swing? AWT? something else?

    To get proper help on a forum, you need to lean to be specific about your problem. Posting a SSCCE (Short, Self Contained, Correct (Compilable), Example) will always ensure that you get better help sooner.

    i am getting error at line 2(if(!..
    When seeking help with an error, always post the complete, unedited error message or stack trace.

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

  3. #3
    blustar angel is offline Member
    Join Date
    Aug 2012
    Posts
    17
    Blog Entries
    1
    Rep Power
    0

    Default Re: problem with key typed event of textfeild

    here is the erroe.sorry i could not enclose it in code.
    Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - unexpected type
    required: value
    found: class
    at HOMEPAGE.tf3KeyTyped(HOMEPAGE.java:7149)
    at HOMEPAGE.access$4900(HOMEPAGE.java:22)
    at HOMEPAGE$57.keyTyped(HOMEPAGE.java:1164)
    at java.awt.Component.processKeyEvent(Component.java: 6460)
    at javax.swing.JComponent.processKeyEvent(JComponent. java:2829)
    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:1893)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEv ent(DefaultKeyboardFocusManager.java:752)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKe yEvent(DefaultKeyboardFocusManager.java:1017)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAsse rtions(DefaultKeyboardFocusManager.java:889)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent (DefaultKeyboardFocusManager.java:717)
    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:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102 )
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    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:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 673)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:97)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: problem with key typed event of textfeild

    Well, if you can't compile your source code you shouldn't be trying to run it. Post the compiler error.

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

Similar Threads

  1. How to replace typed characters?
    By Collinryans in forum New To Java
    Replies: 3
    Last Post: 05-25-2010, 04:50 AM
  2. Replies: 4
    Last Post: 04-23-2009, 09:37 PM
  3. how select date form calendar to textFeild
    By the swan in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 01:16 PM
  4. how select date form calendar to textFeild
    By the swan in forum AWT / Swing
    Replies: 1
    Last Post: 03-31-2009, 07:59 PM
  5. First Typed via video instruction
    By ZAXTHEGREAT in forum New To Java
    Replies: 15
    Last Post: 07-23-2007, 05:27 PM

Posting Permissions

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