我存储的用户输入来显示从一个ArrayList输出到一个类BarInfo的ArrayList。该类需要多个数据:字符串,布尔值,整数。然后我想要显示按JTextArea中输入的顺序存储的数据。现在说用户输入一个栏的数据和所有必要的信息。当他们显示数据时,它的工作正确。然而,如果一个以上的杆被输入时,或之后加入另一杆,它显示与不同的数据的数据的多个版本。试图在JTextArea中
例如,如果两个条被输入的显示将两个条的不同时间从它们两者混合不同量的int数据的显示,而不是仅仅将第一杆,然后第二个。
这是我的课吧:
class BarInfo
{
private final String barLoc, barName, v="Vodka", w="Whiskey", r="Rum",
g="Gin", b="Brandy";
private final boolean music, food;
private final int vCount, wCount, rCount, gCount, bCount;
public BarInfo(String l, String n, boolean m, boolean f, int v, int w,
int r, int g, int b)
{
this.barLoc = l;
this.barName = n;
this.music = m;
this.food = f;
this.vCount = v;
this.wCount = w;
this.rCount = r;
this.gCount = g;
this.bCount = b;
}
@Override
public String toString()
{
return "The bar is located at: " + barLoc + " \nThe bar is named: " + barName
+ "\nLive Music: " + music + "\nFood Service: " + food + "\n"
+ "Liquor currently in stock (bottles):\n" + v + ": " + vCount
+ "\n" + w + ": " + wCount + "\n" + r + ": " + rCount + "\n"
+ g + ": " + gCount + "\n" + b + ": " + bCount + "\n\n";
}
}
而且我的显示代码:
for(int i=0; i<barList.size(); i++)
{
jTextAreaDisplay.append(jTextAreaDisplay.getText()
+ barList.get(i).toString() + "\n\n");
}
我猜我的for循环是有点过,但我没有看到它。任何帮助将不胜感激。
UPDATE 产量预计说,2条:
酒吧位于:(barLoc)
酒吧被命名为:(barName)
现场音乐:(true或假)
餐饮服务:(真或假)
当前酒玉珠:
伏特加=(量)
威士忌=(量)
朗姆酒=(量)
杜松子酒=(量)
白兰地=(量)
然后与它的数据中的第二栏。我所得到的就像这两个条形输入中的6-7个不同的条形。从2条
新格式的输出输入:
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Kendall
The bar is named: sgd
Live Music: false
Food Service: false
Liquor currently in stock (bottles):
Vodka: 10
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
The bar is located at: Miami Beach
The bar is named: Wet
Live Music: true
Food Service: true
Liquor currently in stock (bottles):
Vodka: 20
Whiskey: 0
Rum: 0
Gin: 0
Brandy: 0
什么输出你好吗,和你希望得到什么样的输出? – Mureinik
我更新了上面的代码以显示输出示例。 – diggz
你确定你是不是以某种方式将数据输入ArrayList中多次?同样在你的循环中添加它,你正在调用'JTextArea。追加“,它将新文本添加到该区域的末尾,但是您正在使用当前文本而不仅仅是新文本提供它。这将导致文本重复(但我不知道为什么你的第一个酒吧重复六次,而不是两次)。 – Matthew