Textfield正在等待用户输入 [英] TextField waiting for a user input

查看:31
本文介绍了Textfield正在等待用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获得了一个JTextfield、一个GetText方法和一个用于存储记录在Jextfield上的数字的数组。

JTextField tf1 = new JTextField();
frame.add(tf1);

String tfone = tf1.getText();
int one = Integer.parseInt(tfone);

int[][] array = new int[4][5]; 
array[0][0] = one;
array[0][1] = otherValues...
这里问题是,代码执行所有代码,所以不需要等待用户输入到Jextfield中。如何让jextfield等待,直到用户登录。执行Integer.Parseint?

我无法使用其他方法更改JextField,因为我使用的是图形用户环境。

推荐答案

代码如下:

JTextField tf1 = new JTextField();
frame.add(tf1);

JButton b = new JButton();
b.setText("Solve");
b.setBounds(30, 140, 110, 30);

b.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) 
            {
                String tfone = tf1.getText();
                int one = Integer.parseInt(tfone);

                int[][] array = new int[4][5]; 
                array[0][0] = one;
                array[0][1] = otherValues...
             //Here you can complete the rest of functions

});

frame.add(b);

一旦用户按下按钮,代码将结束其执行。

这篇关于Textfield正在等待用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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