java - 每次单击按钮时如何将值写入不同的文本字段?
问题描述
我无法克服这个问题,需要您的帮助
每次我单击停止按钮时,都会在上面的字段中生成一个随机数。我想要做的是将每个数字保存在左侧字段中。文本字段的名称为 textField_0、textField_1、textField_2 等。
izvucen = rnd.nextInt(31) + 1;
randomField.setText(Integer.toString(izvucen));
textField_i.setText(Integer.toString(izvucen)); // critical line, need to replace "i" with something
i++;
解决方案
您可以在创建所有文本字段时将它们放在一个列表中,并通过索引访问它们
txtFields.get(i).setText(...)
或将所有字段放入地图 ( Map<Integer, TextField>
) 并通过以下方式访问特定字段get()
mapOfTextFields.get(i).setText()
推荐阅读
- java - 致命错误 XXX.pom:3:3:文档中根元素之前的标记必须格式正确
- c# - LINQ 选择子记录错误“查询包含投影”
- vb.net - 无法使用 VB 应用程序在 ASP.Net MVC 上查明空引用异常
- node.js - 如何在安装角度时摆脱这个错误?
- django - 从 Django 的视图中显示多行文本
- c# - 创建 json 文件时的生产出现错误 500 内部服务器错误
- node.js - 我在猫鼬模式中的模式车辆键不应该为空
- javascript - Jquery切片代码给错误请帮助我
- firebase - NotificationHubClient 来自 .net 核心的推送通知
- ajax - 从 AbstractDefaultAjaxBehavior 中的请求中检索多部分数据