通过GUI使用扫描仪类 [英] Using scanner class with a GUI
问题描述
我正在使用java swing创建我的GUI,并使用扫描器类来获取从JTextFields输入到服务器的信息.这有可能吗?
I'm using java swing to create my GUI and using the scanner class to get the information inputted from the JTextFields across to the server. is this possible and if so how?
推荐答案
这不是Swing的工作原理. Scanner
仅用于命令行输入.如果您有JTextField
,只需对其调用.getText()
方法.
That isn't how Swing works. Scanner
is only for command-line input. If you have a JTextField
, just call the .getText()
method on it.
JTextField myField = new JTextField();
...
String currentText = myField.getText();
Swing
是基于事件的.您可能想要一个JButton
,并使该JButton
导致单击该文本时将其提交到服务器.为此,您需要一个ActionListener
.有关更多信息,请参见下面的教程:
http://docs.oracle.com/javase/tutorial/uiswing/components /textfield.html
Swing
is event-based. You probably want to have a JButton
and have that JButton
cause the text to be submitted to the server when it is clicked. For that, you'll need an ActionListener
. See the tutorial below for more information:
http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html
这篇关于通过GUI使用扫描仪类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!