通过GUI使用扫描仪类 [英] Using scanner class with a GUI

查看:73
本文介绍了通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆