1
我正在尝试执行反复加法计算。这应该从“数量”文本框中获取当前数量和保存的数量(要保存的总数量),并在“结果”标题下输出总计结果。 View of tabbed page for calculation.代号1:为流体跟踪器执行计算
我试过下面的代码,但它包含错误并使用对话框输出结果(这不是我想要的)。
addItem.addComponent(selectItem);
TextField quantity = new TextField("", "Quantity (ml or g)", 4, TextArea.NUMERIC);
addItem.addComponent(quantity);
Button add = new Button("Add");
addItem.addComponent(add);
TextArea results = new TextArea("Results");
addItem.addComponent(results);
//TextArea total = new TextArea("Add Item");
//addItem.addComponent(total);
//--------------------------------------------------------------
add.addActionListener((ActionEvent ev) -> {
Storage s = Storage.getInstance();
Integer addition = 0;
// Read my "Hello World" string back from storage
addition = (Integer)s.readObject("total");
int d = Int.parseInt(quantity.getText());
Integer total = addition + quantity;
// Save the "Hello World" string to storage
s.writeObject("total", total);
Dialog.show("", total, "OK", "Cancel");
});
//--------------------------------------------------------------
return addItem;
因此,我将不胜感激关于如何在代码中实现这一点的任何建议和指导。