Results 1 to 3 of 3
  1. #1
    NaturalE is offline Member
    Join Date
    Feb 2011
    Posts
    3
    Rep Power
    0

    Default Only Accepting Numeric inputs, disabled letters!

    When asking an input from the user in java ( in the command prompt ) how do you do it in such a way that the letters are all disabled and only numbers can be pressed?

    for example i asked the user to choose from 1 to 9... he may press a letter, to prevent him from doing this i want to disable all the letters

    i remember in C, we did this because in C you could save user input in integer but i java you can only save the input in a string...

  2. #2
    glina126 is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    im not sure how you could do that, but i know you could write a loop that will not go through and display an error if user enter anything but the number from 1 to 9. what exactly are you trying to write?
    Still a newbee.. on chapter 7 of 15 in the book "Starting out with Java", by Tony Gaddis. :) (GUIs!!!! :D)

  3. #3
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    There is no standard way to ignore particular keypresses in a command line application in Java. In fact there's no way to even detect that a key was pressed.

    Once you have input you are free to interpret it as a numberic value or whatever you like, but, whether Java or C, this is quite different from ignoring keypresses.

Similar Threads

  1. Replies: 0
    Last Post: 09-10-2009, 01:35 PM
  2. JXL, Numeric data issue
    By only2008 in forum Java Servlet
    Replies: 0
    Last Post: 02-27-2009, 12:36 PM
  3. get numeric value from a text field
    By Lehane_9 in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 04:19 AM
  4. Allowing only numeric values in a TextField
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-01-2008, 11:08 PM
  5. Socket programming - accepting files
    By ravian in forum Networking
    Replies: 2
    Last Post: 11-29-2007, 11:40 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
  •