Tomando la entrada de un campo de texto en una clase y escaneando en una clase diferente

I am trying to make a GUI for a program I have completed and do not want to modify. My problem is the program uses a scanner to get user input and I don't know how to get input from the GUI to the scanner. I know how to use getText() from a text field in the GUI but that doesn't update the scanner so the main program just waits for that input and doesn't continue.

preguntado el 15 de mayo de 13 a las 04:05

1 Respuestas

"I am trying to make a GUI for a program I have completed and do not want to modify."

When you give restrictions such as this, it is usually a good idea to explain more, such as the reasons for the restriction; this understanding often helps us give better answers.

"My problem is the program uses a scanner to get user input and I don't know how to get input from the GUI to the scanner. I know how to use getText() from a text field in the GUI but that doesn't update the scanner so the main program just waits for that input and doesn't continue."

You are trying to do what is next to impossible. The solution: correct your console class so that the user interface portion is separated out, a la MVC, so that the model can be used for either a console program or a GUI program.

So the simple answer is: don't try to do this. Create a well behaved set of classes with decent separation of concerns so that you can re-use classes well.

Respondido el 22 de junio de 14 a las 19:06

Thanks for the fast answer. I didn't want to modify the program because the original program is an assignment and the GUI is extra credit to be turned in separately. I believe that the GUI I turn in would be calling the instructors program not mine. I could be wrong about this though so I will confirm with the professor and see if I can turn in the GUI with a program specifically for the GUI. - OK

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.