如何从JFrame中的文本框接收输入? [英] How do I receive input from a textbox in a JFrame?
本文介绍了如何从JFrame中的文本框接收输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下方法扩展了一个JFrame,但是我需要一个swing文本框来接收double值并将它们存储在一个变量中。文本框必须添加到容器中。
The following method extends a JFrame, but I need a swing textbox inside it to receive double values and store them in a variable. the textbox must be added to the container.
public class myClass extends JFrame{
Container container;
container = getContentPane();
//Item label
JLabel labelText = new JLabel();
...
labelText.setText ("Item:");
container.add( labelText );
//Item name: Textbox
//code to make a textbox, add it to the container, and store the value in a variable goes here
推荐答案
使用 JTextField
:
JTextField field = new JTextField(10);
container.add(field, BorderLayout.SOUTH);
< getText())。
这篇关于如何从JFrame中的文本框接收输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文