File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Making a Scanner (java.util.Scanner) in a jframe? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making a Scanner (java.util.Scanner) in a jframe?" Watch "Making a Scanner (java.util.Scanner) in a jframe?" New topic

Making a Scanner (java.util.Scanner) in a jframe?

johann cruz

Joined: Oct 06, 2013
Posts: 4
is there a way to somehow place a scanner in a text, ex:
type a value for a
[text box aka Scanner]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46320
Yes, but why?
You can pass the text from a text box to the Scanner.
Have you read about text components? There are about three kinds. If you want an input, you usually use a text field, because that is smaller and takes a single line. You can get an int out of a text field like this:-…but there are easier ways to do it.

Please explain what you are trying to do, then we can think how to do it later.
johann cruz

Joined: Oct 06, 2013
Posts: 4
i wan't to make a calculator, actually i have a ready one that works in the console, but i wan't one text feild to be the first number, another to be the second, and in between them will be the operator (+, _, *, /, %)
johann cruz

Joined: Oct 06, 2013
Posts: 4
btw im using switch for the operators, heres the code without Jframe

Bernhard Goetz
Ranch Hand

Joined: Jan 07, 2013
Posts: 57

Hi johann,

What kind of use case do you have?

You can try to emulate the console with the combination of a JTextField - which works like the console input (Enter erases the text and "feeds" the calculator) - and a JTextPane above it - which works as the input log.
Having two textboxes for the operands and a let's say JComboBox in between for the operator seems a bit unhandy for a calculator in my opinion.

Best regards,
Bernhard Goetz
I agree. Here's the link:
subject: Making a Scanner (java.util.Scanner) in a jframe?
It's not a secret anymore!