• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
johann cruz
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to somehow place a scanner in a text, ex:
type a value for a
[text box aka Scanner]
 
Campbell Ritchie
Sheriff
Pie
Posts: 47228
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
btw im using switch for the operators, heres the code without Jframe

 
Bernhard Goetz
Ranch Hand
Posts: 57
1
Java Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic