简体   繁体   English

输入数组到GUI Jtextarea

[英]Input array into GUI Jtextarea

Been trying to add my array, year and size of a house into a GUI, more precisely JTextarea. 一直在尝试将我的房屋,房屋的年数和大小添加到GUI(更确切地说是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 has a simple append method that should make it easy to append the results JTextArea有一个简单的append方法,应该可以很容易地附加结果

For example... 例如...

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");
    }
}

Take a look at How to use text areas for more deatils 看看如何使用文本区域实现更多细节

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

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