Input array into GUI Jtextarea(将数组输入到 GUI Jtextarea)
问题描述
一直在尝试将我的数组、房子的年份和大小添加到 GUI 中,更准确地说是 JTextarea.这样做的最简单方法是什么?还没有完全掌握数据输入.
Been trying to add my array, year and size of a house into a GUI, more precisely JTextarea. What's the simplest way of doing so? Not quite grasped data input yet.
public class House {
private int year;
private int size;
private static int nbrOfHouses;
public static final int MIN_SIZE = 10;
public House(int year, int size) {
this.year = year;
this.size = size;
}
public static int getNbrHouses() {
return nbrOfHouses;
}
public int getYear() {
return year;
}
public int getSize() {
return size;
}
}
House[] myHouse = new House[10];{
myHouse[0] = new House(1902, 120);
myHouse[1] = new House(1954, 180);
myHouse[2] = new House(1995,90);
for(int i=0; i< myHouse.length; i++){
if(myHouse[i]!=null){
System.out.println(myHouse[i].getSize());
}
}
}
推荐答案
JTextArea
有一个简单的 append
方法应该可以轻松附加结果
JTextArea
has a simple append
method that should make it easy to append the results
例如...
for(int i=0; i< myHouse.length; i++){
if(myHouse[i]!=null){
textArea.append("Year: ");
textArea.append(Integer.toString(myHouse[i].getYear()));
textArea.append(". Size: ");
textArea.append(Integer.toString(myHouse[i].getSize()));
textArea.append("
");
}
}
看看 如何使用文本区域更多详情
这篇关于将数组输入到 GUI Jtextarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将数组输入到 GUI Jtextarea


- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 转换 ldap 日期 2022-01-01