私はこのサイトを検索し、他の人が答えを探しています.
小売割引を計算するための GUI を作成しました。情報を入力し、計算ボタンを使用して計算を実行し、JTextArea に表示されるリストに追加できます。次に、新しいアイテム ボタンを使用して領域をクリアします (テキスト フィールドを除く)。2 番目のアイテムの [リストに追加] ボタンをクリックすると機能しますが、テキスト領域に 2 つの情報のコピーが表示されます。情報のコピーを 1 つだけ配置するにはどうすればよいですか?
以下は、「リストに追加」ボタンのイベント リスナーのコードです。
/*
* Private inner class to handle add to list event
*/
private class AddListener implements ActionListener
{
@Override
public void actionPerformed (ActionEvent a)
{
//Get and set sale item name to ItemList object
String name = saleItem.getName();
iL.setName(name);
//Get and set department name to ItemList object
String dept = dP.getDep();
iL.setDpt(dept);
//Get and set original price to ItemList object
String oP = dsP.getOrg();
iL.setOp(oP);
//Get and set sale price to ItemList object
String sP = dsP.getSale();
iL.setSp(sP);
//Add ItemList object to ArrayList
iList.add(iL);
final String text = "Sale Item: \t" + iL.getSIname() +
"\nDepartment: \t" + iL.getDpt() +
"\nOriginal Price: \t$" + iL.getOp() +
"\nSale Price: \t$" + iL.getSp() + "\n\n";
//Add ArrayList to text area
for(int index = 0; index < iList.size(); index++)
{
ItemList iLt = (ItemList)iList.get(index);
itemL.append(text);
}
}
}