how to take input and verify input in Java


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how to take input and verify input in Java

  1. #1
    Join Date
    Jul 2007
    Posts
    3

    how to take input and verify input in Java

    Respected Members,
    I have 3 questions with slight changes, I would be thankful to you if you can help me solve this problem, I consulted some books and web sites but did not found the solution, the questions are as follows:

    1) I want to make a Java console program which when executed will ask the user to enter some input from the key board on the command prompt,now suppose if the user enters Ctrl-F3 than a message would be printed that "you have entered the correct input", but if the user enters any other key or a combination of various key a message will be printed "you did not entered the correct key". Now my question is that how will I take input and after that on what basis will I cehck that a combination of paticular keys(Ctrl-F3) is pressed, I mean that what will be the basis of the IF ceck and what is the thing which I am going to check? If any one cal mail some sample code for this program I would really be thankful, or if you can give some oter important resources?

    2) Now my second question is just an extension fo the first question with some slight variations.The thing which I was doing in previous question on a console based program I will now have to do it in GUI based program, I mean that now when I run my program a form(frame a JFrame or Frame) it will ask the user to enter some input from the key baord again if the user presses Ctrl-F3 than a message will be displayed taht you have entered correct input for any other key or key combinations tahnsome other message will be displayed, now here also my question is the same tat how will I take input,than how will I check this input and on what basis will I identify Ctrl-F3 key press.

    3) The third question is same as the first two questions,but here my Java program is running like a Windows process I mean that when ever I start my computer this program starts nning at the back end in Windows(Win XP OS),and the program is continiously tracking all the key presses by the users if some user enters Ctrl-F3 a message will be displayed and if the user enters any other key or combination of keys than nothing will happen,how can I achive this and again I am asking that on what basis will I check the suer input,what will be the IF check,and how can I take input.

    Please all reply soon because I consulted some books and web sites but did not found the solution,please guide me,I would be thankful to all of you people.

    Thanking You,
    Bilal Ali.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    1. In a non-GUI environment, you would generate a "Please Enter your input" and then capture that input (Scanner or some other IO buffer). Once you have captured the input to a memory location (variable), you would then test the content of that variable and, if it matched, then your program would perform a certain task otherwise do another.

    2. When you have a "GUI component", it can monitor Key presses which generate KeyEvents which can be dispatched to a KeyListener you have implemented. When the Ctrl-F3 combination is detected your program will perform a certain task. Otherwise it will do nothing or will display another message. Take a look at the JavaTutorial Trail on events and Listeners at

    http://java.sun.com/docs/books/tutor...nts/index.html

    3. In order to monitor the events in the operating system, including what key presses are occurring in other programs are doing, you'll need to look at JNI

Similar Threads

  1. Problem with java program
    By jareivy05 in forum Java
    Replies: 9
    Last Post: 12-07-2005, 10:11 PM
  2. validating input in java??
    By atif in forum Java
    Replies: 1
    Last Post: 05-22-2002, 08:48 AM
  3. Too new to trust my self writing JAVA
    By Steven L. Southerland in forum Enterprise
    Replies: 2
    Last Post: 02-24-2001, 01:39 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center