将数组输入到 GUI Jtextarea

编程入门 行业动态 更新时间:2024-10-25 09:30:08
本文介绍了将数组输入到 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

本文发布于:2023-08-01 18:42:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   GUI   Jtextarea

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!