【问题标题】:How do I receive input from a textbox in a JFrame?如何从 JFrame 中的文本框接收输入?
【发布时间】:2013-03-21 01:55:36
【问题描述】:

下面的方法扩展了一个 JFrame,但我需要在其中有一个 swing 文本框来接收双精度值并将它们存储在一个变量中。必须将文本框添加到容器中。

    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

【问题讨论】:

标签: java swing double jtextcomponent documentfilter


【解决方案1】:

使用JTextField

 JTextField field = new JTextField(10);
 container.add(field, BorderLayout.SOUTH);

要获取字段的值,请执行Double.parseDouble(field.getText())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 2021-01-13
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 1970-01-01
    相关资源
    最近更新 更多