官术网_书友最值得收藏!

Time for action – showing the results

The default behavior of the application is to show only the results of the last execution. We need to remove all the results that have been previously added to the resultsLayout component if the user has not checked Keep previous results. To do that, implement your showResults method:

private void showResults(Collection<String> results) {
  if(!checkBox.getValue()) {
    resultsLayout.removeAllComponents();
    
  } else if(resultsLayout.getComponentCount() > 0) {
    resultsLayout.addComponent(new Label("--"));
  }
  
  for(String result : results) {
    resultsLayout.addComponent(new Label(result));
  }
}

What just happened?

If the checkbox is not checked, we can remove all the components in resultsLayout (not in layout, we don't want baffled users here):

resultsLayout.removeAllComponents();

If we don't have to remove previous results, we add a separator and iterate over the results to add each one using a label.

Tip

You can remove single components from layouts using the removeComponent method:

layout.removeComponent(someComponent);

Congratulations! We have finished a useful application. Try implementing your own test sets and learn more about Java performance.

主站蜘蛛池模板: 莎车县| 娱乐| 云和县| 双辽市| 潼南县| 梨树县| 紫金县| 娱乐| 大庆市| 义马市| 吴旗县| 海兴县| 手游| 德清县| 武宣县| 隆德县| 榆树市| 湖口县| 年辖:市辖区| 黄冈市| 中宁县| 九寨沟县| 甘孜县| 黄石市| 青州市| 山西省| 定日县| 乌鲁木齐市| 共和县| 沁源县| 安宁市| 颍上县| 西盟| 南乐县| 关岭| 安溪县| 勐海县| 丹凤县| 临猗县| 双牌县| 长治县|