因此,我无法弄清楚如何使用我从泛型数组列表提交的信息来更新 TextArea。截至目前,该程序创建了一个新订单:
Order d1 = new Order();
然后用户选择一些数据并按下添加按钮,订单被添加到 TextArea。我遇到的问题是我必须将订单添加到列表中的正确位置并每次更新。我只是按一项排序。我不确定如何使用 CompareTo 方法来做到这一点。
public void actionPerformed(ActionEvent event)
{
ArrayList<Drink> DrinkArray = new ArrayList<Drink>();
if (event.getSource() == addcoffeeButton)
{
String coffeesize = (String) sizecoffeelist.getSelectedItem();
double coffeeprice = Double.parseDouble(pricecoffeeTextfield.getText());
String coffeetype = (String) cuptypecoffeelist.getSelectedItem();
String coffeecaffeine = (String) caffeineList.getSelectedItem();
String coffeeroom = (String) roomforcreamList.getSelectedItem();
String coffeeadditional = additionalflavorList.getText();
if ((coffeeadditional.isEmpty()))
coffeeadditional = "No Additional Flavor";
Drink d1 = new Coffee(coffeesize, coffeeprice, coffeetype, coffeecaffeine, coffeeroom, coffeeadditional);
DrinkArray.add(d1);
orderTextArea.append(d1);
因此,在将饮料添加到数组并打印到文本区域之前,我必须将其添加到正确的位置,但我不太确定该怎么做。