We know that Scanner is one of the many ways used for interaction purpose,through java console. Is there any UI equivalent of Scanner other than Swing?
-
3Scanner is not a UI element; it's a text parser. – Paul Aug 04 '11 at 04:41
-
1Your question does not make sense. It might help if you could explain the specific problem you're trying to solve. – Matt Ball Aug 04 '11 at 04:43
-
@Paul: I know that.that's why i asked if there was something equivalent to that,so that i could interact in my UI page (but without using swing) – hari Aug 04 '11 at 04:44
-
@Matt Ball: here I start.I have some java code that has certain functionality.I am interacting with my java code through a set of jsp pages.At a particular position during execution,my code throws an exception,which is of course being handled by "prompting for input". Now the problem is,i don't know how to prompt for input on UI other than swing – hari Aug 04 '11 at 04:49
-
2It would be better if you posted your jsp code. I don't know what's causing the exception but I'm sure that you're on the wrong path with this question. – Paul Aug 04 '11 at 04:51
-
@hari... hold on: JSP? Swing? You have to be clear. Do you want to handle input via Swing UI? A JSP page? Exception handled by prompting for input? I am sorry, but with the amount of information you have given I am unable to get a clear idea of what you exactly _want_... – Nivas Aug 04 '11 at 04:52
-
@nivas: by **Exception handled by prompting for input**, i meant that "Scanner" was used to prompt while using console.But now,i'll have to use a UI instead of console to talk to my java code.I'm not able to figure out how to do that.Also,JOptionsPane is a class of javax.swing package! I'm not supposed to use swing. – hari Aug 04 '11 at 05:03
-
@hari, you say you are not supposed to use swing. Why? Because you are using JSP (a web application?) You will have to be clear on what you want. The way I understand, you are trying to port a console application to a web application, and want a replacement of console input. Is that right? – Nivas Aug 04 '11 at 05:05
3 Answers
StreamTokenizer
is a bit dated, but it's arguably faster. Even without Swing, you still have the TextComponent
classes. The append()
method of TextArea
seems like a good choice.
-
See also [java.awt.Component](http://download.oracle.com/javase/6/docs/api/java/awt/Component.html). – trashgod Aug 04 '11 at 04:57
What do you want to do? Scanner is a utility for making inputs from streams and files easy.
For GUI, you need a GUI element, and the ones java provides are based on swing. You can use JOptionsPane.showInputDialog
for getting basic input and use Scanner
over this string (Scanner
can operate on Files, Streams and Strings. See the constructors of Scanner
.
If you don't want Swing, you can use JFace InputDialog
, or build your own dialog.
Update
Looks like you are porting a console application to a web application, and need an alternative for console inputs.
This depends on console input. If what you are getting from the console is configuration parameters, you can use a properties file or xml file. If what you get is dynamic user input, you have to create a JSP. You probably have a server and a servlet. If not you have write them too.
Try looking for some servlet and JSP tutorials on how to get started.

- 18,126
- 4
- 62
- 76
-
@hari, Why? Because you are using JSP (a web application?) You will have to be clear on what you want. The way I understand, you are trying to port a console application to a web application, and want a replacement of console input. Is that right? – Nivas 0 secs ago edit – Nivas Aug 04 '11 at 05:06
If you want a GUI, then you can use Eclipse's SWT to create a custom dialog box for input.
For displaying messages and retrieving simple input (OK, Cancel, etc.) use org.eclipse.swt.widgets.MessageBox. Here you'll find code snippets.
If you need to retrieve input as a text value, build your own dialog. You can find a custom input box here.

- 123
- 6