-1
 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));          
 System.out.print("Enter your name: ");
 String name = reader.readLine();

can i provide input from java code instead of console ?

Madhawa Priyashantha
  • 9,208
  • 7
  • 28
  • 58
Yogesh Borkhade
  • 578
  • 4
  • 9

2 Answers2

1

You can use a file to do that. Using the same BufferedReader and read the complete input values from the file.

And if not that either, you can't use a simple console project and ask for a graphical input system. You can rather add Java Swing to your project and use a graphically oriented form with text fields for it input.

Safeer Ansari
  • 742
  • 4
  • 12
  • how do i ask for graphical input and how do i use graphically oriented form for input ? – Yogesh Borkhade Nov 26 '17 at 12:37
  • 1
    You can look for a tutorial for Jawa Swing. You won't need to re-create your existing project. All you will have to do is add a Java Swing module to your project. You can find good tutorials easily. – Safeer Ansari Nov 26 '17 at 13:09
0

Use JOptionPane#showInputDialog to get the input with some graphical dialogs from user instead of console. It is not the ideal way for a professional program but it is so easier for now to get started with swing JFrame, JTextField, JComboBox etc. and diving into the world of handling actions of JButton or so.

Example:

String input = JOptionPane.showInputDialog(null, "Please enter your name: ");

More detailed JOptionPane#showInputDialog overloads are available and if you want to create more elegant input dialogs. A quick tutorial can be found here.

STaefi
  • 3,800
  • 1
  • 22
  • 39