• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

user input

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please tell me how do you recieve user input from the user please elaborate in detail
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you mean in console mode or in windows mode?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have to pass some arguments to launch your application you can use this syntax
java NameOfYourApplication arg1 arg2 arg3 ...
You may acces those arguments within your main method (public static void main (String args[])
where args represents the arguments the user have entered
So you may do something like that
if (args[0]==...)
I hope it helps!
 
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To prompt users and get input in a String :
String name = JOptionPane.showInputDialog("Enter name " );

From the API for JOptionPane class at :http://java.sun.com/j2se/1.3/docs/api/

"showConfirmDialog Asks a confirming question, like yes/no/cancel.
showInputDialog Prompt for some input.
showMessageDialog Tell the user about something that has happened.
showOptionDialog The Grand Unification of the above three. "
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abdul,
I guess you are asking a beginner question :
There are two ways:
(1) Through console
Please go thorough the code below

(2) Through GUI
Here is the crude code. You would need to read about ActionListeners to understand this

 
Abdul Latif
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suppose there is a program that takes two numbers from the user and then adds & displays the result.I am talking about this basic input from the user.I hope u r getting me
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks to me like Pradyumna has answered your question. What are you not understanding?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do keep in mind that you can get some input from the user when the user invokes the application at the command line.
java Whatever arg1 arg2
Here's the basic framework that displays all of the command line arguments when invoked from the command line:

Are you getting any ideas yet?
 
Abdul Latif
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
but please tell me how to accecpt multiple agrs like first the user will enter the number that no has to be accecpted & then when the user enters another no that no also has to be accecpted
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abdul,
It sounds like you'll want to implement Pradyumna's example above, adding to it some logic testing the validity of the initial input, then reusing Pradyumna's example if the input was accepted.
If you were to post an example of what you've figured out so far, then others could best help you out.
Good Luck.
 
reply
    Bookmark Topic Watch Topic
  • New Topic