简体   繁体   English

如何在Jtextfield中显示名称,请使用Netbeans单击JButton

[英]How to show names in Jtextfield click on JButton using Netbeans

I am fresher in Netbeans . 我在Netbeans上比较新鲜。 I have a small assignment related Netbeans . 我有一个与Netbeans相关的小任务。 I want to show some names in JTextfield (for example "abcd","ijkl","mnop" etc as next by next) and it must show one by one . 我想在JTextfield中显示一些名称(例如“ abcd”,“ ijkl”,“ mnop”等,接下来依次显示),并且它必须一个一个地显示。 I had create some code which not working properly. 我创建了一些无法正常工作的代码。 I am looking some helps related to it. 我正在寻找一些与此有关的帮助。 Please mention as full code here that I can understand in future.I do not know how to create it. 请在此处提及完整的代码,以备将来使用。我不知道如何创建它。 So i am done it some another ways. 所以我用另一种方式做到了。 But showing error message. 但是显示错误消息。 My code is as follows. 我的代码如下。

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:

    String s[]={"abcd","ijkl","mnop" } ;


 for(int d=0; d<s.length;d++)



  jTextField1.setText(""+s);

}                           

Both these variables should be inside of your class but outside of any method. 这两个变量都应该在类的内部,但不能在任何方法的外部。

String s[]={"abcd","ijkl","mnop" } ;
int i=0;

In action performed method 实际执行方法

if(i>=s.length)
   i=0;

jTextField1.setText(s[i]);
i++;

For the first click, display abcd . 对于第一次单击,显示abcd

Next click, display ijkl . 下一步,显示ijkl

Next click, display mnop . 下一步,显示mnop

But I didn't check it. 但是我没有检查。 Just try it. 去尝试一下。 It will works. 它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM