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

Time for action – adding components as class members

To add UI components as class members, edit your TimeItUI class by adding these variables to it:

private static final TestSet[] testSets = new TestSet[] {
  new LongVsInt(),
  new StringVsStringBuffer(),
  new ShortCircuitVsNoShortCircuit()
};

private VerticalLayout layout = new VerticalLayout();
private ComboBox combo = new ComboBox("Test");
private final TextField textField = new TextField("Number of
                                    iterations", "1000");
private CheckBox checkBox = new CheckBox("Keep previous results");
private Button button = new Button("Time it!");
private VerticalLayout resultsLayout = new VerticalLayout();

What just happened?

The first thing you see, testSets, is just an array of business objects, specifically, an array containing instances of TestSet (take a look at the TestSet interface in the book's source code). Think of TestSet as a single scenario from which we want to obtain timing results. For example, the LongVsInt class will run two tests: one to time a loop controlled by a long object type and another to time a loop controlled by an int object type. If you want to add some testing scenarios, all you must do is to implement the TestSet interface and add a new instance to the testSets array.

主站蜘蛛池模板: 景德镇市| 浦城县| 阿尔山市| 革吉县| 嘉祥县| 玉林市| 河源市| 沙河市| 紫阳县| 嘉善县| 哈密市| 拉萨市| 海城市| 上栗县| 旬阳县| 太仆寺旗| 武穴市| 始兴县| 霍林郭勒市| 哈密市| 平乡县| 牙克石市| 万山特区| 山阴县| 宁都县| 江永县| 盐源县| 昌江| 南皮县| 军事| 印江| 乌兰浩特市| 开封市| 稻城县| 绵阳市| 常宁市| 淳安县| 郯城县| 印江| 弥勒县| 麟游县|