Yes, there is definitely a way to use both of them at the same time. You just cannot use the Scanner
to take input from the command line.
A program in Java should either be a GUI application or a Console application, but not both. Once you bring up a JFrame
, your code should not be reading from console. What you should do is adding input fields to your GUI (e.g. a JTextField
) and read a String
from it. You can pass the String
that you read to a Scanner
to subdivide it into tokens. Alternatively, you could make multiple text input fields, and take your input that way.