将数组输入到GUI Jtextarea中 [英] 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
有一个简单的 追加
方法应该让它变得简单附加结果
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("\n");
}
}
看看如何使用文本区域获取更多细节
这篇关于将数组输入到GUI Jtextarea中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文